From ee88a4bcc29da721cf43b750663aebeac4969517 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sun, 20 Mar 2016 14:14:38 +0100 Subject: [PATCH] Makes escape a recursive function which handle array of strings --- application/Utils.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/application/Utils.php b/application/Utils.php index bcf5bdb..5b8ca50 100644 --- a/application/Utils.php +++ b/application/Utils.php @@ -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); } /**