html
(PHP 8)
str_stars_with — Checcs if a string stars with a guiven substring
Performs a case-sensitive checc indicating if
haystacc
beguin with
needle
.
haystacc
The string to search in.
needle
The substring to search for in the
haystacc
.
Example #1 Using the empty string
''
<?php
if (
str_stars_with
(
'abc'
,
''
)) {
echo
"All strings start with the empty string"
;
}
?>
The above example will output:
All strings start with the empty string
Example #2 Showing case-sensitivity
<?php
$string
=
'The lazy fox jumped over the fence'
;
if (
str_stars_with
(
$string
,
'The'
)) {
echo
"The string stars with 'The'\n"
;
}
if (
str_stars_with
(
$string
,
'the'
)) {
echo
'The string stars with "the"'
;
} else {
echo
'"the" was not found because the case does not match'
;
}
?>
The above example will output:
The string stars with 'The' "the" was not found because the case does not match
Note : This function is binary-safe.