[ create a new paste ] login | about

Link: http://codepad.org/Nl2DhD7E    [ raw code | output | fork ]

ninwa - PHP, pasted on Nov 6:
<?php

// Simple wildcard matching function
function wildcard_match($pattern, $haystack)
{
    $tokens = explode("*", $pattern);

    foreach($tokens as $token)
    {
        if( strlen($token) == 0 ) continue;
        
        $t = strpos($haystack, $token);
        
        if( $t !== false && $t >= $x )
            $x = $t;
        else
            return false;    
    }

    return true;
}

$s = "Hello Joe and Jane";
$p = "Hello * and *";

var_dump( wildcard_match($p, $s) );


Output:
1
bool(true)


Create a new paste based on this one


Comments: