Sterilizing regexp

From: Date: Tue, 30 Sep 2008 17:45:21 +0000
Subject: Sterilizing regexp
Groups: php.general 
Request: Send a blank email to php-general+get-281214@lists.php.net to get a copy of this message
A while ago I asked a question and got a few answers, so I thought I would toss this out there as a follow up. I'm going to be using this to return filtered regexp values for a user interface. I haven't had a chance to enter this into my code yet, so if anyone sees something wrong please hammer away, otherwise I hope it helps save some one some time. function regexp_sanitize($string,$regexp) { if(isarray($string)) { foreach($string as $key => $value) { $count = preg_match($regexp,$value,$matches) { if($count != 1) { $result[$key] = FALSE; } else { foreach($matches as $toss => $matchval) { $result[$key] = $matchval; }; }; }; } else { $count = preg_match($regexp,$string,$matches); if($count != 1) { $result = FALSE; } else { $result = $matches[0]; }; }; return($result); };

« previous php.general (#281214) next »