save.bz
Search

PHP Check if String Starts With Certain Characters in PHP

2 weeks ago  •  443 views
<?php

// PHP Check if String Starts With Certain Characters in PHP

function startsWith($string, $startString) {
$len = strlen($startString);
return (substr($string, 0, $len) === $startString);
}
$word = "cat";
$string = startsWith($word, "cat");
if($string == 1) {
echo 'true';
} else {
echo 'false';
}

?>