note 47696 added to function.preg-match

From: Date: Thu, 25 Nov 2004 13:56:02 +0000
Subject: note 47696 added to function.preg-match
Groups: php.notes 
Request: Send a blank email to php-notes+get-81016@lists.php.net to get a copy of this message
<?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 ---- Manual Page -- http://www.php.net/manual/en/function.preg-match.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+47696 Delete -- http://master.php.net/manage/user-notes.php?action=delete+47696&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47696&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47696&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47696&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47696&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47696&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+47696&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#81016) next »