Sorry for the english, I just installed Linux.
The solution is to use a foreach loop.
If this is 1d array than you should use a function like this:
PHP קוד:
function ArrSpecialChars($array) {
foreach($array as $key=>$val) {
$array[$key] = htmlspecialchars($val);
}
}
But, if it is a 2d or more array you should use something recursive like this:
PHP קוד:
function ArrSpecialChars($array) {
foreach($array as $key=>$val) {
if(is_array($val)) {
$array[$key] = ArrSpecialChars($val);
}
$array[$key] = htmlspecialchars($val);
}
return $array;
}
Of cures this one will work for both cases.
Edit:
You can use this function as a master function, for strings to arrays..
PHP קוד:
function SpecialChars($text) {
if(is_array($text)) {
foreach($text as $key=>$val) {
if(is_array($val)) {
$text[$key] = SpecialChars($val);
}
$text[$key] = htmlspecialchars($val);
}
return $text;
}
elseif(is_string($text)) {
$text = htmlspecialchars($text);
return $text;
}
else {
return false;
}
}