25
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;

}
1 Etoile2 Etoiles3 Etoiles4 Etoiles5 Etoiles (6 votes, note : 4.83 sur 5)

Catégories : PHP / MySQL, Programmation

Un commentaire pour “Comment convertir un texte en UTF-8”

  1. ced dit :
    Le 20/08/2008 à 15:14:03

    Génial ton code.

    merci

Laisser un commentaire

Archives :

| décembre 2008 (1) | octobre 2008 (2) | septembre 2008 (3) | mai 2008 (1) | mars 2008 (4) | février 2008 (3) | décembre 2007 (16) | novembre 2007 (2) | juin 2007 (1) | mai 2007 (2) | avril 2007 (1) | mars 2007 (2) | février 2007 (1) | janvier 2007 (3) |
© 2009 Naeh.net | Thème par DemusDesign (Modifié par Naeh), Theme Lab | Powered by WordPress

Naeh.net