Sterilizing regexp

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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);
}; 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux