Makes escape a recursive function which handle array of strings

This commit is contained in:
ArthurHoaro 2016-03-20 14:14:38 +01:00
parent 89baf23ddf
commit ee88a4bcc2
1 changed files with 11 additions and 3 deletions

View File

@ -63,14 +63,22 @@ function endsWith($haystack, $needle, $case=true)
/**
* Htmlspecialchars wrapper
* Support multidimensional array of strings.
*
* @param string $str the string to escape.
* @param mixed $input Data to escape: a single string or an array of strings.
*
* @return string escaped.
*/
function escape($str)
function escape($input)
{
return htmlspecialchars($str, ENT_COMPAT, 'UTF-8', false);
if (is_array($input)) {
$out = array();
foreach($input as $key => $value) {
$out[$key] = escape($value);
}
return $out;
}
return htmlspecialchars($input, ENT_COMPAT, 'UTF-8', false);
}
/**