note 89384 added to function.array-filter

From: Date: Thu, 05 Mar 2009 10:16:14 +0000
Subject: note 89384 added to function.array-filter
Groups: php.notes 
Request: Send a blank email to php-notes+get-151509@lists.php.net to get a copy of this message
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 ) ---- Server IP: 193.95.141.37 Probable Submitter: 86.43.202.19 ---- Manual Page -- http://www.php.net/manual/en/function.array-filter.php Edit -- https://master.php.net/note/edit/89384 Del: integrated -- https://master.php.net/note/delete/89384/integrated Del: useless -- https://master.php.net/note/delete/89384/useless Del: bad code -- https://master.php.net/note/delete/89384/bad+code Del: spam -- https://master.php.net/note/delete/89384/spam Del: non-english -- https://master.php.net/note/delete/89384/non-english Del: in docs -- https://master.php.net/note/delete/89384/in+docs Del: other reasons-- https://master.php.net/note/delete/89384 Reject -- https://master.php.net/note/reject/89384 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#151509) next »