PluginProbe
SQLite Database Integration / 2.2.21
SQLite Database Integration v2.2.21
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 2.2.21, at wp-includes/database/php-polyfills.php

69 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 * @package wp-sqlite-integration
10 */
11
12 if ( ! function_exists( 'str_starts_with' ) ) {
13 /**
14 * Check if a string starts with a specific substring.
15 *
16 * @param string $haystack The string to search in.
17 * @param string $needle The string to search for.
18 *
19 * @see https://www.php.net/manual/en/function.str-starts-with
20 *
21 * @return bool
22 */
23 function str_starts_with( string $haystack, string $needle ) {
24 return 0 === strncmp( $haystack, $needle, strlen( $needle ) );
25 }
26 }
27
28 if ( ! function_exists( 'str_contains' ) ) {
29 /**
30 * Check if a string contains a specific substring.
31 *
32 * @param string $haystack The string to search in.
33 * @param string $needle The string to search for.
34 *
35 * @see https://www.php.net/manual/en/function.str-contains
36 *
37 * @return bool
38 */
39 function str_contains( string $haystack, string $needle ) {
40 return '' === $needle || false !== strpos( $haystack, $needle );
41 }
42 }
43
44 if ( ! function_exists( 'str_ends_with' ) ) {
45 /**
46 * Check if a string ends with a specific substring.
47 *
48 * @param string $haystack The string to search in.
49 * @param string $needle The string to search for.
50 *
51 * @see https://www.php.net/manual/en/function.str-ends-with
52 *
53 * @return bool
54 */
55 function str_ends_with( string $haystack, string $needle ) {
56 if ( '' === $needle || $needle === $haystack ) {
57 return true;
58 }
59
60 if ( '' === $haystack ) {
61 return false;
62 }
63
64 $needle_length = strlen( $needle );
65
66 return $needle_length <= strlen( $haystack ) && 0 === substr_compare( $haystack, $needle, -$needle_length );
67 }
68 }
69