Re: array walk?
| From: | Michael Southworth | Date: | Thu, 28 Jun 2007 16:44:01 +0000 |
| Subject: | Re: array walk? | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-28161@lists.php.net to get a copy of this message | ||
Looks like the answer is in the manual entry for array_walk_recursive
http://php.net/array_walk_recursive
*Note: * If *funcname* needs to be working with the actual values of the
array, specify the first parameter of *funcname* as a
reference<http://www.php.net/manual/en/language.references.php>.
Then, any changes made to those elements will be made in the original array
itself.
Try using a wrapper around strip_tags which tags a reference as its first
argument
function array_walk_strip_tags(&$string){
$string = strip_tags($string);
}
PHP is essentially only passing a copy of $a[i] and stripping the tags from
the copy without changing the actual values of $a. Passing by reference
ensures that you modify the entries in $a itself. How this is handled below
the hood is slightly more complex and I don't have a ton of experience with
how PHP specifically handles that sort of thing, but it looks like that will
at least point you in the right direction.
-Michael
On 6/28/07, Juan Ignacio Borda <webmaster@baexporta.gba.gov.ar> wrote:
this code doesn't work on my PHP Version 5.2.1 (i'm trying to protect a stie from XSS) <?php $a=Array(); $a[]='<i>como</i>'; $a[]=Array('<b>hola</b>','hello'); array_walk_recursive($a,'strip_tags'); echo "<pre>"; var_dump($a); echo "</pre>"; ?> it outputs: <pre>array(2) { [0]=> string(11) "<i>como</i>" [1]=> &array(2) { [0]=> string(11) "<b>hola</b>" [1]=> string(5) "hello" } } </pre> any clues? -- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php