array_to_csv.php
3 years ago
date_format.php
3 years ago
exact_range.php
3 years ago
number_formatter.php
3 years ago
relative_range.php
3 years ago
request.php
3 years ago
salt.php
3 years ago
security.php
3 years ago
singleton.php
3 years ago
string.php
3 years ago
timezone.php
3 years ago
url.php
3 years ago
wp-async-request.php
3 years ago
string.php
33 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP; |
| 4 | |
| 5 | class StringUtil |
| 6 | { |
| 7 | /** These functions are copied verbatim from the WordPress polyfills added in 5.9. |
| 8 | * They allow us to use these PHP 8 functions with PHP 7 and WP 5.5 */ |
| 9 | public static function str_contains($haystack, $needle) |
| 10 | { |
| 11 | return '' === $needle || false !== strpos($haystack, $needle); |
| 12 | } |
| 13 | |
| 14 | public static function str_starts_with($haystack, $needle) |
| 15 | { |
| 16 | if ('' === $needle) { |
| 17 | return true; |
| 18 | } |
| 19 | |
| 20 | return 0 === strpos($haystack, $needle); |
| 21 | } |
| 22 | |
| 23 | public static function str_ends_with($haystack, $needle) |
| 24 | { |
| 25 | if ('' === $haystack && '' !== $needle) { |
| 26 | return false; |
| 27 | } |
| 28 | $len = strlen($needle); |
| 29 | |
| 30 | return 0 === substr_compare($haystack, $needle, -$len, $len); |
| 31 | } |
| 32 | } |
| 33 |