xxxxxxxxxx
<?php
if (str_starts_with('abc', '')) {
echo "All strings start with the empty string";
}
?>
xxxxxxxxxx
phpCopy<?php
$string = "Mr. Peter";
if(strncmp($string, "Mr.", 3) === 0){
echo "The string starts with the desired substring.";
}else
echo "The string does not start with the desired substring.";
?>
xxxxxxxxxx
phpCopy<?php
$string = "Mr. Peter";
if(substr($string, 0, 3) === "Mr."){
echo "The string starts with the desired substring.";
}else
echo "The string does not start with the desired substring.";
?>
xxxxxxxxxx
phpCopy<?php
$string = "Mr. Peter";
if(strpos( $string, "Mr." ) === 0){
echo "The string starts with the desired substring.";
}else
echo "The string does not start with the desired substring.";
?>
xxxxxxxxxx
phpCopy<?php
$string = "mr. Peter";
if(strncasecmp($string, "Mr.", 3) === 0){
echo "The string starts with the desired substring.";
}else
echo "The string does not start with the desired substring.";
?>
xxxxxxxxxx
$string = "Test demo";
if(@strncmp($string, 'Test', 4) === 0){
echo "The string starts with the desired substring.";
} else {
echo "The string does not start with the desired substring.";
}