Created
June 18, 2013 11:01
-
-
Save esthezia/5804445 to your computer and use it in GitHub Desktop.
PHP - Sanitize a multidimensional array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Sanitize a multidimensional array | |
* | |
* @uses htmlspecialchars | |
* | |
* @param (array) | |
* @return (array) the sanitized array | |
*/ | |
function purica_array ($data = array()) { | |
if (!is_array($data) || !count($data)) { | |
return array(); | |
} | |
foreach ($data as $k => $v) { | |
if (!is_array($v) && !is_object($v)) { | |
$data[$k] = htmlspecialchars(trim($v)); | |
} | |
if (is_array($v)) { | |
$data[$k] = purica_array($v); | |
} | |
} | |
return $data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, mind if i take this. Was looking for it ;)
Regards Jerome