Re: array walk?

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

 



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



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux