Re: Easier way to clean GET Variables ?

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

 



On Mon, 2005-08-29 at 11:07, Jay Paulson wrote:
> > Can anybody point to a good resource of a collection of filtering for
> > common inputs such as those listed by Chris above?...
> >
> > I've searched for that and generally found one of two things:
> >
> > 1. Nothing useful.
> > 2. A system so baroque and complex and with so much other baggage, it
> > would be impossible to integrate.  See 1.
> >
> > I'm looking more for code snippets or specific Regex functions for
> > each item, rather than a monolithic Borg-like "filtering package" and
> > have never one I liked.
> >
> > That could be mostly my fault due to peculiar requirements, but there
> > it is.
> 
> I'd like to know this too.  As well as the examples are in this thread 
> I don't think they handled multi dimensional arrays.  It'd be nice if 
> they did. :)

I've adapted my previous solution for multi-dimensional retrieval using
unix directory style path lookup:

function arrayGetValue( &$array, $path, $default=null )
{
    $subArray = &$array;

    $bits = explode( '/', $path );

    foreach( $bits as $aBit )
    {
        if( isset( $subArray[$aBit] ) )
        {
            $subArray = &$subArray[$aBit];
        }
        else
        {
            unset( $subArray );
            $subArray = $default;

            break;
        }
    }

    return $subArray;
}

function arrayGetValueProcessed( &$array, $path, $process, $default=null
)
{
    return $process( arrayGetValue( $array, $path, $default ) );
}

function cleanser( $value )
{
    return mysql_real_escape_string( trim( $value ) ) );
}

//
// Example.
//
$title = arrayGetValueProcessed( $games, $userId.'/favourite/rpg' )


Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

-- 
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