str_starts_with
Description
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); ?>
true
2
<? $haystack = "haystack"; $needle = "needle"; $return = str_starts_with($haystack, $needle); var_export($return); ?>
false
3
<? $haystack = "empty needle returns true"; $needle = ""; $return = str_starts_with($haystack, $needle); var_export($return); ?>
true
4
<? $haystack = "case Case 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); ?>
truefalsefalse