blob: 7d4bf9d859cbf024b52a24644b2aa0a587fe2260 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
<?php
declare(strict_types=1);
namespace mystic\forum\utils;
final class StringUtils {
use StaticClass;
public static function camelToSnake(string $camelCase): string {
$result = '';
for ($i = 0; $i < strlen($camelCase); $i++) {
$char = $camelCase[$i];
if (ctype_upper($char)) {
$result .= '_' . strtolower($char);
} else {
$result .= $char;
}
}
return ltrim($result, '_');
}
}
|