public static function like($pattern, $string, $caseSensitive = true): bool
    {
        if ($pattern === $string) {
            return true;
        }

        // Preg flags
        $flags = $caseSensitive ? '' : 'i';

        // Escape any regex special characters
        $pattern = preg_quote($pattern, '#');

        // Unescaped * which is our wildcard character and change it to .*
        $pattern = str_replace('\*', '.*', $pattern);

        return (bool)preg_match('#^' . $pattern . '$#' . $flags, $string);
    }
public static function like($pattern, $string, $caseSensitive = true): bool
    {
        if ($pattern === $string) {
            return true;
        }

        // Preg flags
        $flags = $caseSensitive ? '' : 'i';

        // Escape any regex special characters
        $pattern = preg_quote($pattern, '#');

        // Unescaped * which is our wildcard character and change it to .*
        $pattern = str_replace('\*', '.*', $pattern);

        return (bool)preg_match('#^' . $pattern . '$#' . $flags, $string);
    }
public static function like ( $ pattern , $ string , $ caseSensitive = true ) : bool { if ( $ pattern === $ string ) { return true ; } // Preg flags $ flags = $ caseSensitive ? '' : 'i' ; // Escape any regex special characters $ pattern = preg_quote ( $ pattern , '#' ) ; // Unescaped * which is our wildcard character and change it to .* $ pattern = str_replace ( '\*' , '.*' , $ pattern ) ; return ( bool ) preg_match ( '#^' . $ pattern . '$#' . $ flags , $ string ) ; }
Check if a given string matches a given pattern.

@param  string $pattern Pattern of string expected
@param  string $string  String that need to be matched
@param  bool   $caseSensitive
@return bool
Check if a given string matches a given pattern .