1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Jasny; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Turn a sentence, camelCase, snake_case or kabab-case into camelCase |
7
|
|
|
* |
8
|
|
|
* @param string $string |
9
|
|
|
* @return string |
10
|
|
|
*/ |
11
|
|
|
function camelcase($string) |
|
|
|
|
12
|
|
|
{ |
13
|
6 |
|
$sentence = preg_replace('/[\W_]+/', ' ', $string); |
14
|
6 |
|
return lcfirst(str_replace(' ', '', ucwords($sentence))); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Turn a sentence, camelCase, snake_case or kabab-case into StudlyCase |
19
|
|
|
* |
20
|
|
|
* @param string $string |
21
|
|
|
* @return string |
22
|
|
|
*/ |
23
|
|
|
function studlycase($string) |
|
|
|
|
24
|
|
|
{ |
25
|
6 |
|
$sentence = preg_replace('/[\W_]+/', ' ', $string); |
26
|
6 |
|
return str_replace(' ', '', ucwords($sentence)); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Turn a sentence, camelCase, StudlyCase or kabab-case into snake_case |
31
|
|
|
* |
32
|
|
|
* @param string $string |
33
|
|
|
* @return string |
34
|
|
|
*/ |
35
|
|
|
function snakecase($string) |
|
|
|
|
36
|
|
|
{ |
37
|
6 |
|
$sentence = strtolower(preg_replace('/([a-z0-9])([A-Z])/', '$1 $2', $string)); |
38
|
6 |
|
return preg_replace('/[\W\_]+/', '_', $sentence); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Turn a sentence, camelCase, StudlyCase or snake_case into kabab-case |
43
|
|
|
* |
44
|
|
|
* @param string $string |
45
|
|
|
* @return string |
46
|
|
|
*/ |
47
|
|
|
function kababcase($string) |
|
|
|
|
48
|
|
|
{ |
49
|
6 |
|
$sentence = strtolower(preg_replace('/([a-z0-9])([A-Z])/', '$1 $2', $string)); |
50
|
6 |
|
return preg_replace('/[\W\_]+/', '-', $sentence); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Turn StudlyCase, camelCase, snake_case or kabab-case into a sentence. |
55
|
|
|
* |
56
|
|
|
* @param string $string |
57
|
|
|
* @return string |
58
|
|
|
*/ |
59
|
|
|
function uncase($string) |
|
|
|
|
60
|
|
|
{ |
61
|
6 |
|
$snake = strtolower(preg_replace('/([a-z0-9])([A-Z])/', '$1 $2', $string)); |
62
|
6 |
|
$sentence = preg_replace('/[-_\s]+/', ' ', $snake); |
63
|
|
|
|
64
|
6 |
|
return $sentence; |
65
|
|
|
} |
66
|
|
|
|
This check looks for functions that have already been defined in other files.
Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the
@ignore
annotation.See also the PhpDoc documentation for @ignore.