Created
September 13, 2013 17:12
-
-
Save sycobuny/6553392 to your computer and use it in GitHub Desktop.
A quick hack to make it easier to sanitize outputs en masse before displaying them to the user.
This file contains hidden or 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 | |
function sanitize_for_html(&$entity, $flags = ENT_QUOTES) { | |
if (is_array($entity)) { | |
$iterator = $entity; | |
} | |
elseif (is_object($entity)) { | |
$iterator = get_object_vars($entity); | |
} | |
else { | |
$entity = htmlentities($entity, $flags); | |
return $entity; | |
} | |
foreach ($iterator as $field => $value) { | |
$clean = sanitize_for_html($value); | |
if (is_array($entity)) { | |
$entity[$field] = $value; | |
} | |
else { | |
$entity->$field = $value; | |
} | |
} | |
return $entity; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment