Ver Mensaje Individual
  #1 (permalink)  
Antiguo 22/12/2009, 14:30
Avatar de pato12
pato12
 
Fecha de Ingreso: septiembre-2007
Ubicación: Salta
Mensajes: 1.620
Antigüedad: 16 años, 7 meses
Puntos: 101
Detectar codificacion utf-8

Hola,
Hay algun modo de dectar la codificacion? yo encontre esto:
Código PHP:
Ver original
  1. // http://php.apsique.com/node/536
  2. function detetarCodificacion($texto){
  3.     $c=0;
  4.     $ascii=true;
  5.     for($i=0;$i<strlen($texto);$i++){
  6.         $byte=ord($texto[$i]);
  7.         if($c>0){
  8.             if(($byte>>6)!=0x2)
  9.                 return 3;
  10.             else
  11.                 $c--;
  12.         }elseif($byte&0x80){
  13.             $ascii=false;
  14.             if(($byte>>5)==0x6)
  15.                 $c=1;
  16.             elseif(($byte>>4)==0xE)
  17.                 $c=2;
  18.             elseif(($byte>>3)==0x14)
  19.                 $c=3;
  20.             else
  21.                 return 3;
  22.         }
  23.     }
  24.     return ($ascii)?2:1;
  25. }
Pero no detecta bien aveses.
Gracias
Salu2
__________________
Half Music - www.halfmusic.com