Page 1 of 1

htmlentities on an array

Posted: Mon Dec 05, 2005 3:55 am
by AGISB
Whats the easiest way to use htmlentities to a complete array not knowing the elements of the array?

I am thinking foreach but it escapes me how to change the array value within the foreach.

Re: htmlentities on an array

Posted: Mon Dec 05, 2005 3:59 am
by Chris Corbyn
AGISB wrote:Whats the easiest way to use htmlentities to a complete array not knowing the elements of the array?

I am thinking foreach but it escapes me how to change the array value within the foreach.

Code: Select all

foreach ($array as $key => $value)
{
    $array[$key] = htmlentities($value);
}

print_r($array);

Posted: Mon Dec 05, 2005 4:10 am
by onion2k
I'd use..

Code: Select all

array_walk($array,create_function('&$s', '$s = htmlentities($s);'));
;)

Posted: Mon Dec 05, 2005 4:27 am
by Jenk
http://us3.php.net/manual/en/function.array-map.php

Code: Select all

$array = array_map("htmlentities", $array);

Posted: Mon Dec 05, 2005 5:13 am
by m3mn0n
Jenk wins the contest =P :wink:

Posted: Mon Dec 05, 2005 5:49 am
by Chris Corbyn
Sami wrote:Jenk wins the contest =P :wink:
Fully! What a great function :)