Codice PHP:
function unicode_decode($str){
return preg_replace("#/u([0-9A-F]{4})#ie", "hex2str(\"$1\")", $str);
}
function hex2str($hex) {
$r = '';
for ($i = 2; $i < strlen($hex) - 1; $i += 2){
$r .= chr(hexdec($hex[$i] . $hex[$i + 1]));
}
return $r;
}
function pulisci($string) {
$string=json_encode($string);
$string = str_replace("\u", "/u", $string);
echo "partenza:" . $string . "
</br>";
$string = unicode_decode($string);
echo "decodificata:" . $string . "
</br>";
$string=substr($string, 0, -1);
$string=substr($string, 1);
return $string;
}
Qualcosa cambia..
partenza:"\n\n/u00b0./u2022/u00b0/u2022./u2605diventa fan/u2605./u2022/u00b0/u2022./u00b0 /u00a9"
decodificata:"°."°".diventa fan."°".° ©"
L'originale è °.•°•.★diventa fan★.•°•.° ©
Su un sito che la visualizza bene c'è
<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> (come il mio sito)