[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-windows
Subject:    Re: [PHP-WIN] array walk?
From:       "Michael Southworth" <mikesouthworth () gmail ! com>
Date:       2007-06-28 16:44:01
Message-ID: cbda40880706280944y165bd208o42ef6786f3ef2c63 () mail ! gmail ! com
[Download RAW message or body]


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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic