htmlspecialchars() for arrays / nested arrays
Platform: PHP
Published May 15, 2011
Updated May 15, 2011
This is a very simple function that will run htmlspecialchars() on every value in an array. The function is recursive (calls itself) so even if it holds nested arrays it will still work.
For example:
Would become:
function htmlspecial_array(&$variable) {
foreach ($variable as &$value) {
if (!is_array($value)) { $value = htmlspecialchars($value); }
else { htmlspecial_array($value); }
}
}