Re[4]: [PHP-ES] Sobre problema con el encoding

From: Date: Fri, 27 Feb 2004 14:21:25 +0000
Subject: Re[4]: [PHP-ES] Sobre problema con el encoding
References: 1  Groups: php.general.es 
Request: Send a blank email to general-es+get-46069@lists.php.net to get a copy of this message
Fran escribió: F> Si las funciones de XSL internamente utilizan UTF-8 y pasan de la F> codificacion que le pongas en el encoding serviria tu funcion, como puedes F> tener al final unos determinados caracteres si cada encoding los convierte F> de una forma? F> No estaria mal que comentases esta funcion. la saqué del manual de php sino recuerdo mal. Se pone claro la codificación de la página a 8859-1 <META http-equiv="Content-Type" CONTENT="text/html; charset=iso-8859-1"> En fin, a mi me funciona //////////////////////////////////////////////////////////////// // // Esta funcion convierte UTF-8 hacia ISO-8859-1 sin tener // caract. MB en apache: // //////////////////////////////////////////////////////////////// function utf8toiso8859($string) { $returns = ""; $UTF8len = array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 5, 6); $pos = 0; $antal = strlen($string); do { $c = ord($string[$pos]); $len = $UTF8len[($c >> 2) & 0x3F]; switch ($len) { case 6: $u = $c & 0x01; break; case 5: $u = $c & 0x03; break; case 4: $u = $c & 0x07; break; case 3: $u = $c & 0x0F; break; case 2: $u = $c & 0x1F; break; case 1: $u = $c & 0x7F; break; case 0: /* unexpected start of a new character */ $u = $c & 0x3F; $len = 5; break; } while (--$len && (++$pos < $antal && $c = ord($string[$pos]))) { if (($c & 0xC0) == 0x80) $u = ($u << 6) | ($c & 0x3F); else { /* unexpected start of a new character */ $pos--; break; } } if ($u <= 0xFF) $returns .= chr($u); else $returns .= '?'; } while (++$pos < $antal); return $returns; }

« previous php.general.es (#46069) next »