note 67159 added to function.in-array
| From: | musik at krapplack dot de | Date: | Sun, 04 Jun 2006 12:52:58 +0000 |
| Subject: | note 67159 added to function.in-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-113188@lists.php.net to get a copy of this message | ||
I needed a version of in_array() that supports wildcards in the haystack. Here it is:
<?php
function my_inArray($needle, $haystack) {
# this function allows wildcards in the array to be searched
foreach ($haystack as $value) {
if (true === fnmatch($value, $needle)) {
return true;
}
}
return false;
}
$haystack = array('*krapplack.de');
$needle = 'www.krapplack.de';
echo my_inArray($needle, $haystack); # outputs "true"
?>
Unfortunately, fnmatch() is not available on Windows or other non-POSIX compliant systems.
Cheers,
Thomas
----
Server IP: 217.160.72.57
Probable Submitter: 85.179.30.102
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.in-array.php
Edit -- http://master.php.net/note/edit/67159
Del: integrated -- http://master.php.net/note/delete/67159/integrated
Del: useless -- http://master.php.net/note/delete/67159/useless
Del: bad code -- http://master.php.net/note/delete/67159/bad+code
Del: spam -- http://master.php.net/note/delete/67159/spam
Del: non-english -- http://master.php.net/note/delete/67159/non-english
Del: in docs -- http://master.php.net/note/delete/67159/in+docs
Del: other reasons-- http://master.php.net/note/delete/67159
Reject -- http://master.php.net/note/reject/67159
Search -- http://master.php.net/manage/user-notes.php