str_starts_with()
Performs a case-sensitive check indicating if the haystack begins with needle.
Performs a case-sensitive check indicating if the haystack begins with needle.
1 time — 0.000001 sec (speed of light) | 50000 times — 0.001 sec (speed of light)
No Hooks.
Return
true|false
. True if $haystack starts with $needle, otherwise false.
Usage
str_starts_with( $haystack, $needle );
- $haystack(string) (required)
- The string to search in.
- $needle(string) (required)
- The substring to search for in the $haystack.
Examples
#1 Demo
str_starts_with( 'ABC', 'A' ); // true str_starts_with( 'ABC', 'C' ); // false // case sensitive str_starts_with( 'ABC', 'a' ); // false // all lines begin with an empty string str_starts_with( 'abc', '' ); // true
Changelog
Since 5.9.0 | Introduced. |
str_starts_with() str starts with code WP 6.7.1
function str_starts_with( $haystack, $needle ) { if ( '' === $needle ) { return true; } return 0 === strpos( $haystack, $needle ); }