str_starts_with()
Checks if the string starts with the specified substring. Case sensitive.
This is a polyfill for the new php function str_starts_with() introduced in PHP version 8.0.
See also similar functions:
1 time — 0.000001 sec (speed of light) | 50000 times — 0.001 sec (speed of light)
No Hooks.
Returns
null. True if the string ($haystack) starts with the substring ($needle), false otherwise.
Usage
str_starts_with( $haystack, $needle );
- $haystack(string) (required)
- Hay - the string we are checking.
- $needle(string) (required)
- Needle - the substring that should be at the beginning of another string.
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
str_starts_with() str starts with code WC 10.7.0
function str_starts_with(?string $haystack, ?string $needle): bool { return p\Php80::str_starts_with($haystack ?? '', $needle ?? ''); }