str_starts_with
Check if the string begins with the given substring
Function name: str_starts_with()
Function function: determines whether a string starts with the specified prefix.
Applicable version: PHP 8.0.0 and above.
Syntax: bool str_starts_with ( string $haystack , string $needle )
parameter:
Return value:
Example:
$haystack = "Hello, world!"; $needle = "Hello"; if (str_starts_with($haystack, $needle)) { echo "字符串以指定前缀开始"; } else { echo "字符串不以指定前缀开始"; }
Output:
字符串以指定前缀开始
Notes:
substr($haystack, 0, strlen($needle)) === $needle
.