Here is a shim for older php versions. It works for php 5.4 and above.
<?php
if (!function_exists('str_starts_with')) {
function str_starts_with($haystack, $needle) {
$haystackArray = str_split($haystack);
$needleArray = str_split($needle);
$matches = [];
foreach ($needleArray as $offset => $needleChar) {
if(!array_key_exists($offset, $haystackArray)){
break;
}
$haystackChar = $haystackArray[$offset];
if ($needleChar === $haystackChar) {
$matches[$offset] = $haystackChar;
continue;
}
if ($needleChar !== $haystackChar) {
break;
}
}
if (empty($matches)) {
return false;
}
return true;
}
}
$string = 'The lazy fox jumped over the fence';
if (str_starts_with($string, 'The')) {
echo "The string starts with 'The'\n";
}