Check if string starts with a specified string PHP

> String starts with string
> String startsWith()

Description
Check if string starts with a specified string


function startsWith( $fullString, $part ) {
    return strncmp($fullString, $part, strlen($part)) === 0;
}

$val = startsWith( "abcdef", "ab" ); // true
$val = startsWith( "abcdef", "cd" ); // false

function startsWith( $fullString, $part ) {
    return substr_compare($fullString, $part, 0, strlen($part)) === 0;
}

$val = startsWith( "abcdef", "ab" ); // true

function startsWith( $fullString, $part ) {
    return substr($fullString, 0, strlen($part)) === $part;
}

$val = startsWith( "abcdef", "ab" ); // true

SEE ALSO