str_starts_with php code example
Example 1: php string starts with
substr( $http, 0, 4 ) === "http";
substr( $https, 0, 5 ) === "https";
Example 2: Check if a String Starts With a Specified String in PHP
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.";
?>
Example 3: Check if a String Starts With a Specified String in PHP
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.";
?>