Created
September 6, 2012 09:05
-
-
Save oscar-broman/3653399 to your computer and use it in GitHub Desktop.
UTF8 encode array/object structure in PHP
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 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
Thanks for the idea, tipochka, but it still does not work. Here is an example for non-working code, since I got no idea how to change the different -Elements. In the follwing example for the line "foreach ($input as $k=>$val)" $k is twice 'bar'. That occurs errors. And foreach by reference is not possible here (Fatal-Error).