note 85398 deleted from function.preg-match by cmb
| From: | cmb@php.net | Date: | Sun, 28 Oct 2018 10:45:21 +0000 |
| Subject: | note 85398 deleted from function.preg-match by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-209540@lists.php.net to get a copy of this message | ||
Note Submitter: wjaspers4[at]gmail[dot]com
----
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;
}
?>