grateful
0
Q:

php starts with

//php check if first four characters of a string = http
substr( $http, 0, 4 ) === "http";
//php check if first five characters of a string = https
substr( $https, 0, 5 ) === "https";
2
function stringStartsWith($haystack,$needle,$case=true) {
    if ($case){
        return strpos($haystack, $needle, 0) === 0;
    }
    return stripos($haystack, $needle, 0) === 0;
}

function stringEndsWith($haystack,$needle,$case=true) {
    $expectedPosition = strlen($haystack) - strlen($needle);
    if ($case){
        return strrpos($haystack, $needle, 0) === $expectedPosition;
    }
    return strripos($haystack, $needle, 0) === $expectedPosition;
}
echo stringStartsWith("Hello World","Hell"); // true
echo stringEndsWith("Hello World","World"); // true
3
function startsWith ($string, $startString) { 
    $len = strlen($startString); 
    return (substr($string, 0, $len) === $startString); 
} 
2
function startsWith($haystack, $needle)
{
     $length = strlen($needle);
     return (substr($haystack, 0, $length) === $needle);
}

function endsWith($haystack, $needle)
{
    $length = strlen($needle);
    if ($length == 0) {
        return true;
    }

    return (substr($haystack, -$length) === $needle);
}
0

New to Communities?

Join the community