note 24880 added to function.ereg
| From: | bool at boolsite dot net | Date: | Tue, 03 Sep 2002 15:58:01 +0000 |
| Subject: | note 24880 added to function.ereg | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-36072@lists.php.net to get a copy of this message | ||
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
--
http://www.php.net/manual/en/function.ereg.php
http://master.php.net/manage/user-notes.php?action=edit+24880
http://master.php.net/manage/user-notes.php?action=delete+24880
http://master.php.net/manage/user-notes.php?action=reject+24880