Total Complexity | 5 |
Total Lines | 42 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
10 | trait StringFunctions |
||
11 | { |
||
12 | /** |
||
13 | * does a haystack start with a needle ? |
||
14 | * @param $haystack string the string to search in |
||
15 | * @param $needle string the string to search for |
||
16 | * @return bool |
||
17 | */ |
||
18 | public function startsWith(string $haystack, string $needle): bool |
||
19 | { |
||
20 | $length = strlen($needle); |
||
21 | return (substr($haystack, 0, $length) === $needle); |
||
22 | } |
||
23 | |||
24 | /** |
||
25 | * Does a haystack end with a needle |
||
26 | * @param $haystack string the string to search in |
||
27 | * @param $needle string the string to search for |
||
28 | * @return bool |
||
29 | */ |
||
30 | public function endsWith(string $haystack, string $needle): bool |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * Remove the tail of a string |
||
42 | * @param $string string to slice apart |
||
43 | * @param $tail string the string to remove |
||
44 | * @return string |
||
45 | */ |
||
46 | public function removeFromEnd(string $string, string $tail): string |
||
52 | } |
||
53 | } |