Re: Sterilizing regexp

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

 



On Wed, Oct 1, 2008 at 2:53 AM, Per Jessen <per@xxxxxxxxxxxx> wrote:> Frank Stanovcak wrote:>>> I've got to pass about 9 or 10 calls to it, some of which will be>> arrays, and I have to do it from several different places.  Felt this>> was a bit more elegant than hard coding the pregmatches unless there>> is an  easier way.>> Code elegance is usually in the eye of the beholder, but personally I> would have stuck to a set of hardcoded preg_matches().>>> /Per Jessen, Zürich
Just to throw out another option...  I use a little input filtervalidation library I wrote.  I wanted to use something pre-existingbut I was stuck on php4 at the time so I modeled it after a fewdifferent frameworks, specifically stubbles & solar.
Basically it works by creating classes that are filters.  Thesefilters can be applied to any variable and they will either return thevariable upon validation success, null on failure, or a user definedoverride default.  Along with the filters are some helpers to createcomposite filters to do simple AND's & OR's.  I also have another onefor applying a filter to an array.  There are also hooks into therequest object to apply these validation filters.
If I were to handle this case I could do this:
$array = $request->getFiltered(new my_InputFilter_ValidateArray(newmy_InputFilter_ValidateRegex('/regex/')), 'postkey',my_Request::POST);
ValidateArray recursively applies the passed filter to all entries inthe array making sure the value matches.

[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