note 76654 deleted from function.preg-replace by felipe
| From: | felipe@php.net | Date: | Sun, 23 Mar 2008 23:00:56 +0000 |
| Subject: | note 76654 deleted from function.preg-replace by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-137404@lists.php.net to get a copy of this message | ||
Note Submitter: alexandre at NO-DAMN-SPAM-gaigalas dot net
----
Match and replace for arrays. Useful for parsing entire $_POST
<?php
function array_preg_match(array $patterns, array $subjects, &$errors = array()) {
$errors = array();
foreach ($patterns as $k => $v) preg_match($v, $subjects[$k]) or $errors[$k] = TRUE;
return count($errors) == 0 ? TRUE : FALSE;
}
function array_preg_replace(array $patterns, array $replacements, array $subject) {
$r = array();
foreach ($patterns as $k => $v) $r[$k] = preg_replace($v, $replacements[$k], $subject[$k]);
return $r+$subject;
}
?>