25fév/082
Comment convertir un texte en UTF-8
voici une fonction simple mais efficace pour convertir un texte en UTF-8 sans se préoccuper de sa provenance (encodage d'origine).
setlocale(LC_ALL, 'fr_FR.utf8'); //selon la configuration du serveur cela peut être : fr_FR mb_detect_order(array('UTF-8', 'ISO-8859-1', 'ISO-8859-15', 'Windows-1252')); //l'extention mb_string est installée par defaut sur php5 function toUTF8($string){ $from = mb_detect_encoding($string); if ($from != 'UTF-8') { $string = mb_convert_encoding($string, 'UTF-8', $from); } return $string; } |