| 1 |
<?php |
| 2 |
/** |
| 3 |
* Polyfills for php 7 & 8 functions |
| 4 |
* |
| 5 |
* @package wp-sqlite-integration |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! function_exists( 'str_starts_with' ) ) { |
| 9 |
/** |
| 10 |
* Check if a string starts with a specific substring. |
| 11 |
* |
| 12 |
* @param string $haystack The string to search in. |
| 13 |
* @param string $needle The string to search for. |
| 14 |
* |
| 15 |
* @see https://www.php.net/manual/en/function.str-starts-with |
| 16 |
* |
| 17 |
* @return bool |
| 18 |
*/ |
| 19 |
function str_starts_with( string $haystack, string $needle ) { |
| 20 |
return empty( $needle ) || 0 === strpos( $haystack, $needle ); |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
if ( ! function_exists( 'str_contains' ) ) { |
| 25 |
/** |
| 26 |
* Check if a string contains a specific substring. |
| 27 |
* |
| 28 |
* @param string $haystack The string to search in. |
| 29 |
* @param string $needle The string to search for. |
| 30 |
* |
| 31 |
* @see https://www.php.net/manual/en/function.str-contains |
| 32 |
* |
| 33 |
* @return bool |
| 34 |
*/ |
| 35 |
function str_contains( string $haystack, string $needle ) { |
| 36 |
return empty( $needle ) || false !== strpos( $haystack, $needle ); |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
if ( ! function_exists( 'str_ends_with' ) ) { |
| 41 |
/** |
| 42 |
* Check if a string ends with a specific substring. |
| 43 |
* |
| 44 |
* @param string $haystack The string to search in. |
| 45 |
* @param string $needle The string to search for. |
| 46 |
* |
| 47 |
* @see https://www.php.net/manual/en/function.str-ends-with |
| 48 |
* |
| 49 |
* @return bool |
| 50 |
*/ |
| 51 |
function str_ends_with( string $haystack, string $needle ) { |
| 52 |
return empty( $needle ) || substr( $haystack, -strlen( $needle ) === $needle ); |
| 53 |
} |
| 54 |
} |
| 55 |
|