Re: Re: filter_input and $_POST deep array

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

 



On 09/23/2011 06:16 PM, jean-baptiste verrey wrote:
> foreach cannot work in this situation has filter_input does not work
> recursively and work only on the first level of $_POST (or $_GET) 
> so the best solution seems to be to use filter_var($_POST['var']['var2']);
I was sure filter_input would work on nested levels. But it doesn't as
you point out.

You could do something like this if you want to filter the same types

array_walk_recursive($_POST, function(&$value) {
    $value = filter_var($value, FILTER_SANITIZE_STRING);
});

>
> Thanks anyway
>
> On 23 September 2011 17:13, Thijs Lensselink <dev@xxxxxxxx
> <mailto:dev@xxxxxxxx>> wrote:
>
>     On 09/23/2011 03:17 PM, jean-baptiste verrey wrote:
>     > seems that the only solution is to still use $_POST and use
>     filter_var
>     > instead, it could have been better!
>     You can foreach the $_Post['login'] array and use filter_input on each
>     iteration to do the filtering.
>     Or maybe the filter_input_array is a better place to look at. The
>     manual
>     is your friend.
>
>     http://php.net/manual/en/function.filter-input.php
>
>     Besides that. Calling filter_var two times won't kill you!
>     > On 23 September 2011 14:11, jean-baptiste verrey <
>     > jeanbaptiste.verrey@xxxxxxxxx
>     <mailto:jeanbaptiste.verrey@xxxxxxxxx>> wrote:
>     >
>     >> What do you mean? I don't see how I could use foreach there
>     >>
>     >> On 23 September 2011 13:31, Al <news@xxxxxxxxxxxxx
>     <mailto:news@xxxxxxxxxxxxx>> wrote:
>     >>
>     >>>
>     >>> On 9/23/2011 5:51 AM, jean-baptiste verrey wrote:
>     >>>
>     >>>> Hi,
>     >>>>
>     >>>> I have using a form that gives me something like
>     >>>>  $_POST=array(
>     >>>>     'login'=>array(
>     >>>>         'email'=>'hello@xxxxxxxxx <mailto:hello@xxxxxxxxx>',
>     >>>>         'password'=>'123456'
>     >>>>     )
>     >>>> )
>     >>>>
>     >>>> is there a way to use filter_input function to filter the
>     values? I tried
>     >>>> filter_input(INPUT_POST,'**login[email]') but it does not work!
>     >>>>
>     >>>> Regards,
>     >>>>
>     >>>> Jean-Baptiste Verrey
>     >>>>
>     >>>>
>     >>> foreach() in the manual
>     >>>
>     >>> --
>     >>> PHP General Mailing List (http://www.php.net/)
>     >>> To unsubscribe, visit: http://www.php.net/unsub.php
>     >>>
>     >>>
>
>
>     --
>     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