note 85398 added to function.preg-match
| From: | wjaspers4 | Date: | Thu, 28 Aug 2008 14:55:28 +0000 |
| Subject: | note 85398 added to function.preg-match | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-143941@lists.php.net to get a copy of this message | ||
I found this rather useful for testing mutliple strings when developing a regex pattern.
<?php
/**
* Runs preg_match on an array of strings and returns a result set.
* @author wjaspers4[at]gmail[dot]com
* @param String $expr The expression to match against
* @param Array $batch The array of strings to test.
* @return Array
*/
function preg_match_batch( $expr, $batch=array() )
{
// create a placeholder for our results
$returnMe = array();
// for every string in our batch ...
foreach( $batch as $str )
{
// test it, and dump our findings into $found
preg_match($expr, $str, $found);
// append our findings to the placeholder
$returnMe[$str] = $found;
}
return $returnMe;
}
?>
----
Server IP: 209.41.74.194
Probable Submitter: 209.150.201.146
----
Manual Page -- http://www.php.net/manual/en/function.preg-match.php
Edit -- https://master.php.net/note/edit/85398
Del: integrated -- https://master.php.net/note/delete/85398/integrated
Del: useless -- https://master.php.net/note/delete/85398/useless
Del: bad code -- https://master.php.net/note/delete/85398/bad+code
Del: spam -- https://master.php.net/note/delete/85398/spam
Del: non-english -- https://master.php.net/note/delete/85398/non-english
Del: in docs -- https://master.php.net/note/delete/85398/in+docs
Del: other reasons-- https://master.php.net/note/delete/85398
Reject -- https://master.php.net/note/reject/85398
Search -- https://master.php.net/manage/user-notes.php