Created
January 8, 2012 14:32
-
-
Save dominikzogg/1578542 to your computer and use it in GitHub Desktop.
php utf-8 encoding function
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 encode_to_utf8 ($input) { | |
$output = $input; | |
if($encoding == get_encoding($input)) { | |
$output = iconv($encoding, "UTF-8", $output); | |
} | |
return($output); | |
} | |
function get_encoding ($input) { | |
$encondings = array("ASCII", "UTF-8", "ISO-8859-1"); | |
$input_md5 = md5($input); | |
foreach($encondings as $enconding) { | |
$sample = iconv($enconding, $enconding, $input); | |
if(md5($sample) == $input_md5) { | |
return($enconding); | |
} | |
} | |
return(false); | |
} | |
function recursive_encode_to_utf8 ($array) { | |
if(is_array($array)) { | |
foreach($array as $key => $value) { | |
if(is_array($value)) { | |
$tmparray[$key] = recursive_encode_to_utf8($value); | |
} | |
else { | |
$tmparray[$key] = encode_to_utf8($value); | |
} | |
} | |
return($tmparray); | |
} | |
else { | |
return(encode_to_utf8($array)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
line 5 is wrong.