Forked from esthezia/php-sanitize-multidimensional-array.php
Last active
August 29, 2015 14:26
-
-
Save Kcko/b188359330998b796681 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