25
fév
2008
fév
2008
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;
}
Catégories : PHP / MySQL, Programmation
Un commentaire pour “Comment convertir un texte en UTF-8”
-
ced dit :
Le 20/08/2008 à 15:14:03Génial ton code.
merci

(6 votes, note : 4.83 sur 5)