From cdee4dde8b7c362e41d8aead3eef83eebcd8f01f Mon Sep 17 00:00:00 2001 From: Cerdic <cedric@yterium.com> Date: Sat, 21 Jul 2007 12:08:15 +0000 Subject: [PATCH] =?UTF-8?q?implementer=20la=20conversion=20iso-8859-1=20ve?= =?UTF-8?q?rs=20utf-8=20en=20direct,=20sans=20passer=20par=20unicode,=20po?= =?UTF-8?q?ur=20des=20questions=20de=20rapidit=C3=A9=20(cas=20le=20plus=20?= =?UTF-8?q?frequent=20des=20conversions=20de=20charset=20lors=20des=20impo?= =?UTF-8?q?rts=20de=20fichiers=20dans=20un=20site=20en=20utf8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ecrire/inc/charsets.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/ecrire/inc/charsets.php b/ecrire/inc/charsets.php index 3c68f4c2ff..6800647358 100644 --- a/ecrire/inc/charsets.php +++ b/ecrire/inc/charsets.php @@ -351,6 +351,31 @@ function unicode2charset($texte, $charset='AUTO') { // (les caracteres non resolus sont transformes en {) // http://doc.spip.org/@importer_charset function importer_charset($texte, $charset = 'AUTO') { + static $trans = array(); + // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite ! + if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset']=='utf-8')){ + $texte = corriger_caracteres_windows($texte, 'iso-8859-1',$GLOBALS['meta']['charset']); + if (init_mb_string()) { + if ($order = mb_detect_order() # mb_string connait-il $charset? + AND mb_detect_order($charset)) { + $s = mb_convert_encoding($texte, 'utf-8', $charset); + } + mb_detect_order($order); # remettre comme precedemment + return $s; + } + // Sinon, peut-etre connaissons-nous ce charset ? + if (!isset($trans[$charset])) { + global $CHARSET; + if ($cset = load_charset($charset) + AND is_array($CHARSET[$cset])) + foreach ($CHARSET[$cset] as $key => $val) { + $trans[$charset][chr($key)] = unicode2charset('&#'.$val.';'); + } + } + if (count($trans[$charset])) + return str_replace(array_keys($trans[$charset]),array_values($trans[$charset]),$texte); + return $texte; + } return unicode2charset(charset2unicode($texte, $charset)); } -- GitLab