note 24880 deleted from function.ereg by didou
| From: | didou@php.net | Date: | Sun, 07 Dec 2003 02:59:21 +0000 |
| Subject: | note 24880 deleted from function.ereg by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-61556@lists.php.net to get a copy of this message | ||
Note Submitter: bool@boolsite.net
----
to use jokers (* and ?) in string comparaison use this function :
function jokercmp($string,$mask){
static $in=array('.', '^', '$', '{', '}',
'(', ')', '[', ']', '+', '*',
'?');
static $out=array('\\.', '\\^', '\\$', '\\{',
'\\}', '\\(', '\\)', '\\[', '\\]',
'\\+', '.*', '.');
$mask='^'.str_replace($in,$out,$mask).'$';
return(ereg($mask,$string));
}
examples :
if(jokercmp('myfile.txt','*.txt')) [...] // this is true
if(jokercmp('file001.jpg','file??.jpg')) [...] // this is false