str_starts_with
Checks if a string starts with a given substring
Syntax
str_starts_with ( string $haystack , string $needle ) : bool
Parameters
haystack
The string to search in.
needle
The substring to search for in the haystack.
Return
Returns TRUE if haystack begins with needle, FALSE otherwise.
Examples
1
<? $haystack = "needle haystack haystack"; $needle = "needle"; $return = str_starts_with($haystack, $needle); var_export($return); ?>
2
<? $haystack = "an empty needle returns true"; $needle = ""; $return = str_starts_with($haystack, $needle); var_export($return); ?>
3
<? $haystack = "case"; $needle1 = "Case"; $needle2 = "case"; $needle3 = "CASE"; $return1 = str_starts_with($haystack, $needle1); $return2 = str_starts_with($haystack, $needle2); $return3 = str_starts_with($haystack, $needle3); var_export($return1); var_export($return2); var_export($return3); ?>