Skip to content

Instantly share code, notes, and snippets.

@oscar-broman
Created September 6, 2012 09:05
Show Gist options
  • Save oscar-broman/3653399 to your computer and use it in GitHub Desktop.
Save oscar-broman/3653399 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);
}
}
}
?>
@seba2305
Copy link

thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment