I've been trying using array_map
to convert characters to HTML entities with htmlentities()
like this:
$lang = array_map('htmlentities', $lang);
My array looks like this:
$lang = array();
$lang['var_char1']['varchar2'] = 'Some Text';
But I keep getting this errors:
Warning: htmlentities() expects parameter 1 to be string, array given in /home/user/public_html/foo/lang/en.inc.php on line 1335
Does anyone know what could be the problem? Thank you!
array_map() doesn't work recursively. If you know your array is always two levels deep you could loop through it and use array_map on the sub-arrays.
if you like quotes
multiple array in post, get, dll
$lang['var_char1']['varchar2']
defines a multidimensional array, so each element of$lang
is also an array.array_map()
iterates through$lang
, passing an array tohtmlentities()
instead of a string.Use
array_walk_recursive
.array_map
doesn't work with multidimensional arrays:Because $lang is a two dimensional array, so it won't work
For two dimensional array you need to use for loop