note 91475 added to function.glob
| From: | sven at NOSPAM dot sven dot globalunix dot org | Date: | Thu, 11 Jun 2009 16:22:31 +0000 |
| Subject: | note 91475 added to function.glob | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-156781@lists.php.net to get a copy of this message | ||
If you want to use wildcard expressions (like they are used by glob() ) to search on strings, you
can use this function:
<?php
function match_wildcard( $wildcard_pattern, $haystack ) {
$regex = str_replace(
array("\*", "\?"), // wildcard chars
array('.*','.'), // regexp chars
preg_quote($wildcard_pattern)
);
return preg_match('/^'.$regex.'$/is', $haystack);
}
$test = "foobar and blob\netc.";
var_dump(
match_wildcard('foo*', $test), // TRUE
match_wildcard('bar*', $test), // FALSE
match_wildcard('*bar*', $test), // TRUE
match_wildcard('**blob**', $test), // TRUE
match_wildcard('*a?d*', $test), // TRUE
match_wildcard('*etc**', $test) // TRUE
);
?>
----
Server IP: 69.147.83.197
Probable Submitter: 87.166.211.207
----
Manual Page -- http://www.php.net/manual/en/function.glob.php
Edit -- https://master.php.net/note/edit/91475
Del: integrated -- https://master.php.net/note/delete/91475/integrated
Del: useless -- https://master.php.net/note/delete/91475/useless
Del: bad code -- https://master.php.net/note/delete/91475/bad+code
Del: spam -- https://master.php.net/note/delete/91475/spam
Del: non-english -- https://master.php.net/note/delete/91475/non-english
Del: in docs -- https://master.php.net/note/delete/91475/in+docs
Del: other reasons-- https://master.php.net/note/delete/91475
Reject -- https://master.php.net/note/reject/91475
Search -- https://master.php.net/manage/user-notes.php