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_Util.php
3 years ago
Timezone.php
3 years ago
URL.php
3 years ago
WP_Async_Request.php
3 years ago
String_Util.php
33 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP\Utils; |
| 4 | |
| 5 | class String_Util |
| 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 |