PluginProbe
SQLite Database Integration / 3.0.1
SQLite Database Integration v3.0.1
3.0.2 3.0.1 trunk 2.1.13 2.1.14 2.1.15 2.1.16 2.2.0 2.2.1 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.17 2.2.18 2.2.19 2.2.2 2.2.20 2.2.21 2.2.22 2.2.23 2.2.3 All 32 releases
sqlite-database-integration / wp-includes / database / php-polyfills.php

php-polyfills.php in SQLite Database Integration 3.0.1, at wp-includes/database/php-polyfills.php

67 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Polyfills for PHP 8.0 string functions.
4 *
5 * Implementation follows the Symfony polyfill-php80 package.
6 *
7 * @see https://github.com/symfony/polyfill-php80
8 */
9
10 if ( ! function_exists( 'str_starts_with' ) ) {
11 /**
12 * Check if a string starts with a specific substring.
13 *
14 * @param string $haystack The string to search in.
15 * @param string $needle The string to search for.
16 *
17 * @see https://www.php.net/manual/en/function.str-starts-with
18 *
19 * @return bool
20 */
21 function str_starts_with( string $haystack, string $needle ) {
22 return 0 === strncmp( $haystack, $needle, strlen( $needle ) );
23 }
24 }
25
26 if ( ! function_exists( 'str_contains' ) ) {
27 /**
28 * Check if a string contains a specific substring.
29 *
30 * @param string $haystack The string to search in.
31 * @param string $needle The string to search for.
32 *
33 * @see https://www.php.net/manual/en/function.str-contains
34 *
35 * @return bool
36 */
37 function str_contains( string $haystack, string $needle ) {
38 return '' === $needle || false !== strpos( $haystack, $needle );
39 }
40 }
41
42 if ( ! function_exists( 'str_ends_with' ) ) {
43 /**
44 * Check if a string ends with a specific substring.
45 *
46 * @param string $haystack The string to search in.
47 * @param string $needle The string to search for.
48 *
49 * @see https://www.php.net/manual/en/function.str-ends-with
50 *
51 * @return bool
52 */
53 function str_ends_with( string $haystack, string $needle ) {
54 if ( '' === $needle || $needle === $haystack ) {
55 return true;
56 }
57
58 if ( '' === $haystack ) {
59 return false;
60 }
61
62 $needle_length = strlen( $needle );
63
64 return $needle_length <= strlen( $haystack ) && 0 === substr_compare( $haystack, $needle, -$needle_length );
65 }
66 }
67