Changeset 57457
- Timestamp:
- 01/30/2024 06:14:54 PM (11 months ago)
- Location:
- branches/5.0
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.0
- Property svn:mergeinfo changed
/trunk merged: 52040,56015-56016
- Property svn:mergeinfo changed
-
branches/5.0/src/wp-includes/compat.php
r43221 r57457 538 538 } 539 539 } 540 541 if ( ! function_exists( 'str_starts_with' ) ) { 542 /** 543 * Polyfill for `str_starts_with()` function added in PHP 8.0. 544 * 545 * Performs a case-sensitive check indicating if 546 * the haystack begins with needle. 547 * 548 * @since 5.9.0 549 * 550 * @param string $haystack The string to search in. 551 * @param string $needle The substring to search for in the `$haystack`. 552 * @return bool True if `$haystack` starts with `$needle`, otherwise false. 553 */ 554 function str_starts_with( $haystack, $needle ) { 555 if ( '' === $needle ) { 556 return true; 557 } 558 559 return 0 === strpos( $haystack, $needle ); 560 } 561 } 562 563 if ( ! function_exists( 'str_ends_with' ) ) { 564 /** 565 * Polyfill for `str_ends_with()` function added in PHP 8.0. 566 * 567 * Performs a case-sensitive check indicating if 568 * the haystack ends with needle. 569 * 570 * @since 5.9.0 571 * 572 * @param string $haystack The string to search in. 573 * @param string $needle The substring to search for in the `$haystack`. 574 * @return bool True if `$haystack` ends with `$needle`, otherwise false. 575 */ 576 function str_ends_with( $haystack, $needle ) { 577 if ( '' === $haystack ) { 578 return '' === $needle; 579 } 580 581 $len = strlen( $needle ); 582 583 return substr( $haystack, -$len, $len ) === $needle; 584 } 585 }
Note: See TracChangeset
for help on using the changeset viewer.