1 | <?php |
||
5 | class Str |
||
6 | { |
||
7 | /** |
||
8 | * Converts the underscore_notation to the UpperCamelCase |
||
9 | * |
||
10 | * @param string $string |
||
11 | * @param string $delimiter |
||
12 | * |
||
13 | * @return string |
||
14 | */ |
||
15 | public static function camelize(string $string, string $delimiter = '_'): string |
||
27 | |||
28 | /** |
||
29 | * Check if a string is ends with a given substring. |
||
30 | * public static function endsWith($haystack, $needle) |
||
31 | * |
||
32 | * @param string $haystack |
||
33 | * @param string $needle |
||
34 | * |
||
35 | * @return bool |
||
36 | */ |
||
37 | public static function endsWith(string $haystack, string $needle): bool |
||
41 | |||
42 | /** |
||
43 | * Returns the first string there is between the strings from the parameter start and end. |
||
44 | * |
||
45 | * @param string $haystack |
||
46 | * @param string $start |
||
47 | * @param string $end |
||
48 | * |
||
49 | * @return string |
||
50 | */ |
||
51 | public static function firstStringBetween(string $haystack, string $start, string $end): string |
||
55 | |||
56 | /** |
||
57 | * Lets you determine whether or not a string includes another string. |
||
58 | * |
||
59 | * @param string $needle |
||
60 | * @param string $haystack |
||
61 | * |
||
62 | * @return bool |
||
63 | */ |
||
64 | public static function includes(string $needle, string $haystack): bool |
||
68 | |||
69 | /** |
||
70 | * Compare two strings and returns true if both strings are anagram, false otherwise. |
||
71 | * |
||
72 | * @param string $string1 |
||
73 | * @param string $string2 |
||
74 | * |
||
75 | * @return bool |
||
76 | */ |
||
77 | public static function isAnagram(string $string1, string $string2): bool |
||
81 | |||
82 | /** |
||
83 | * Returns true if the given string is lower case, false otherwise. |
||
84 | * |
||
85 | * @param string $string |
||
86 | * |
||
87 | * @return bool |
||
88 | */ |
||
89 | public static function isLowerCase(string $string): bool |
||
93 | |||
94 | /** |
||
95 | * Returns true if the given string is upper case, false otherwise. |
||
96 | * |
||
97 | * @param string $string |
||
98 | * |
||
99 | * @return bool |
||
100 | */ |
||
101 | public static function isUpperCase(string $string): bool |
||
105 | |||
106 | /** |
||
107 | * Returns true if the given string is a palindrome, false otherwise. |
||
108 | * |
||
109 | * @param string $string |
||
110 | * |
||
111 | * @return bool |
||
112 | */ |
||
113 | public static function palindrome(string $string): bool |
||
117 | |||
118 | /** |
||
119 | * Check if a string is starts with a given substring. |
||
120 | * |
||
121 | * @param string $haystack |
||
122 | * @param string $needle |
||
123 | * |
||
124 | * @return bool |
||
125 | */ |
||
126 | public static function startsWith(string $haystack, string $needle): bool |
||
130 | |||
131 | /** |
||
132 | * Retuns number of vowels in provided string. |
||
133 | * Use a regular expression to count the number of vowels (A, E, I, O, U) in a string. |
||
134 | * |
||
135 | * @param string $string |
||
136 | * |
||
137 | * @return int |
||
138 | */ |
||
139 | public static function countVowels(string $string): int |
||
145 | |||
146 | /** |
||
147 | * Decapitalizes the first letter of the sring and then adds it with rest of the string. Omit the upperRest parameter to keep the |
||
148 | * rest of the string intact, or set it to true to convert to uppercase. |
||
149 | * |
||
150 | * @param string $string |
||
151 | * @param bool $upperRest |
||
152 | * |
||
153 | * @return string |
||
154 | */ |
||
155 | public static function decapitalize(string $string, bool $upperRest = false): string |
||
159 | |||
160 | /** |
||
161 | * Substring a string to specific lenght, but removing whole words |
||
162 | * |
||
163 | * @param string $string |
||
164 | * @param int $to |
||
165 | * |
||
166 | * @return string |
||
167 | */ |
||
168 | public static function substringByWord(string $string, int $to): string |
||
176 | |||
177 | /** |
||
178 | * Convert a number to an excel column letter |
||
179 | * EJ: 'A'+22 = W; |
||
180 | * |
||
181 | * @param string $letter Initial Letter |
||
182 | * @param int $number Number of letters to increase |
||
183 | * |
||
184 | * @return string |
||
185 | */ |
||
186 | public static function letterPlusNumber(string $letter, int $number): string |
||
194 | } |
||
195 |