note 89384 deleted from function.array-filter by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 08:04:01 +0000 |
| Subject: | note 89384 deleted from function.array-filter by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-196786@lists.php.net to get a copy of this message | ||
Note Submitter: marijnk at NOSPAM dot gwobbel dot com
----
I was looking for a function that could filter values from an array using a regular expression
pattern supplied, based on leon at darkk dot net dot ru I created the following:
Description:
Return array of matching values from array using regular expression.
<?php
class array_ereg {
function array_ereg($pattern) { $this->pattern = $pattern; }
function ereg($string) {
return ereg($this->pattern, $string);
}
}
?>
Usage :
<?php
$matches = array_filter($subject, array(new array_ereg($pattern), 'ereg'));
?>
Example:
<?php
$subject = array ("Thumbs.db", "image001.png", "image001.jpg",
"image002.png");
print_r(array_filter($subject, array(new array_ereg("image[0-9]{3}\.png"),
'ereg')));
?>
Outputs:
Array ( [1] => image001.png [3] => image002.png )