Advertisement — Top

Responsive Advertisement

StartsWith() and endsWith() functions in PHP

    <?php


    startsWith() and endsWith() functions in PHP


    function startsWith( $haystack, $needle ) {
        $length = strlen( $needle );
        return substr( $haystack, 0, $length ) === $needle;
    }

    function endsWith( $haystack, $needle ) {
    $length = strlen( $needle );
    if( !$length ) {
        return true;
    }
    return substr( $haystack, -$length ) === $needle;
    }
    Use this if you don't want to use a regex.


Post a Comment

0 Comments