note 47696 deleted from function.preg-match by colder

From: Date: Mon, 18 Jun 2007 18:17:26 +0000
Subject: note 47696 deleted from function.preg-match by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-127584@lists.php.net to get a copy of this message
Note Submitter: zubfatal, root at it dot dk ---- <?php /** * Search through an array using a regular expression, and return an array with the matched values * Note: if $boolMatchesOnly is set to true, a new array will be created, * regardless of $boolNewArray * * @author Tim Johannessen <admin@stillborn.dk> * @version 1.0.0 * @param string $strRegEx Regular expressiom to search through the array * @param array $arrHaystack The array to search through * @param bool $boolNewArray If set to true, the index for the array will be re-assigned - If set to false the existing key value will be used * @return array Returns an array with the matches found in the array */ function array_preg_match($strRegEx = "", $arrHaystack = NULL, $boolNewArray = 0, $boolMatchesOnly = 0) { if (strlen($strRegEx) < 1) { return "ERR: \$strRegEx argument is missing."; } elseif ((!is_array($arrHaystack)) || (!count($arrHaystack) > 0)) { return "ERR: \$arrHaystack is empty, or not an array."; } else { unset($arrTmp); // search through $arrHaystack, and build new array foreach($arrHaystack as $key => $value) { if ($boolMatchesOnly) { if (preg_match_all($strRegEx, $value, $tmpRes)) { $arrTmp[] = $tmpRes; } } else { if (preg_match($strRegEx, $value, $tmpRes)) { if ($boolNewArray) { $arrTmp[] = $value; } else { $arrTmp[$key] = $value; } } } } return $arrTmp; } } ?> // zubfatal

« previous php.notes (#127584) next »