Hi,
I've tried various combinations and permutations of filter_var_array() and have yet to find the answer to this:
Given a rather large associative array, I need to apply FILTER_SANITIZE_STRING with the FILTER_FLAG_ENCODE_HIGH flag to all of the elements in the array.
So:
filter_var_array($my_big_array,FILTER_SANITIZE_STRING);
applies the FILTER_SANITIZE_STRING filter but without the FILTER_FLAG_ENCODE_HIGH flag.
How can I specify FILTER_SANITIZE_STRING + FILTER_FLAG_ENCODE_HIGH with filter_var_array? (easily)
I want to avoid having to create a filter+flag+option array for every element in $my_big_array.
Any Help?
M
Apply a common filter with filter_var_array??
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Apply a common filter with filter_var_array??
I looked at the manual:
http://us2.php.net/manual/en/function.f ... -array.php
It looks like you do this:
http://us2.php.net/manual/en/function.f ... -array.php
It looks like you do this:
Code: Select all
$args = array(
'myelement' => array(
'filter' => FILTER_SANITIZE_STRING,
'flags' => FILTER_FLAG_ENCODE_HIGH,
),
);
filter_var_array($my_big_array, $args);(#10850)
Re: Apply a common filter with filter_var_array??
Thanks for the reply,
But this is what I am trying to avoid.
I have 320 elements in the array, I'd like to apply the common filter+flags to all of them without having to define 320 filter+flags arrays that are all the same:
And I looked at the manual too...You can apply a common filter to all of the elements in one line:
but there is no mention of how to use flags with that filter.
M
But this is what I am trying to avoid.
I have 320 elements in the array, I'd like to apply the common filter+flags to all of them without having to define 320 filter+flags arrays that are all the same:
Code: Select all
$args = array(
'myelement' => array(
'filter' => FILTER_SANITIZE_STRING,
'flags' => FILTER_FLAG_ENCODE_HIGH,
),
'myelement1' => array(
'filter' => FILTER_SANITIZE_STRING,
'flags' => FILTER_FLAG_ENCODE_HIGH,
),
'myelement2' => array(
'filter' => FILTER_SANITIZE_STRING,
'flags' => FILTER_FLAG_ENCODE_HIGH,
),
'myelement3' => array(
'filter' => FILTER_SANITIZE_STRING,
'flags' => FILTER_FLAG_ENCODE_HIGH,
),
'myelement4' => array(
'filter' => FILTER_SANITIZE_STRING,
'flags' => FILTER_FLAG_ENCODE_HIGH,
),
....320 times
);
filter_var_array($my_big_array, $args);
Code: Select all
filter_var_array($my_big_array,FILTER_SANITIZE_STRING);M