Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ArielMejiaDev/503a0214321854fe395a0072c7e45c75 to your computer and use it in GitHub Desktop.
Save ArielMejiaDev/503a0214321854fe395a0072c7e45c75 to your computer and use it in GitHub Desktop.
UTF8 encode array/object structure in PHP
<?php
function utf8_encode_deep(&$input) {
if (is_string($input)) {
$input = utf8_encode($input);
} else if (is_array($input)) {
foreach ($input as &$value) {
utf8_encode_deep($value);
}
unset($value);
} else if (is_object($input)) {
$vars = array_keys(get_object_vars($input));
foreach ($vars as $var) {
utf8_encode_deep($input->$var);
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment