Ver Mensaje Individual
  #10 (permalink)  
Antiguo 20/07/2009, 23:16
iovan
 
Fecha de Ingreso: septiembre-2007
Ubicación: PyRoot
Mensajes: 1.515
Antigüedad: 19 años, 1 mes
Puntos: 188
Respuesta: Poblema la insertar Ñ y tildes en la DB

muchs gracias amigo.

Lo estoy probando, gracias.

EDITO: LA solucion es:

Código PHP:
<?
//INICIO DE LA COMPROBACION DE CARACTERES ESPECIALES
    
class unicode_replace_entities {
        public function 
UTF8entities($content="") {
            
$contents = $this->unicode_string_to_array($content);
            
$swap = "";
            
$iCount = count($contents);
            for (
$o=0;$o<$iCount;$o++) {
                
$contents[$o] = $this->unicode_entity_replace($contents[$o]);
                
$swap .= $contents[$o];
            }
            return 
mb_convert_encoding($swap,"UTF-8");
        }

        public function 
unicode_string_to_array( $string ) { 
            
$strlen = mb_strlen($string);
            while (
$strlen) {
                
$array[] = mb_substr( $string, 0, 1, "UTF-8" );
                
$string = mb_substr( $string, 1, $strlen, "UTF-8" );
                
$strlen = mb_strlen( $string );
            }
            return 
$array;
        }

        public function 
unicode_entity_replace($c) { 
            
$h = ord($c{0});   
            if (
$h <= 0x7F) {
                return 
$c;
            } else if (
$h < 0xC2) {
                return 
$c;
            }
           
            if (
$h <= 0xDF) {
                
$h = ($h & 0x1F) << 6 | (ord($c{1}) & 0x3F);
                
$h = "&#" . $h . ";";
                return 
$h;
            } else if (
$h <= 0xEF) {
                
$h = ($h & 0x0F) << 12 | (ord($c{1}) & 0x3F) << 6 | (ord($c{2}) & 0x3F);
                
$h = "&#" . $h . ";";
                return 
$h;
            } else if (
$h <= 0xF4) {
                
$h = ($h & 0x0F) << 18 | (ord($c{1}) & 0x3F) << 12 | (ord($c{2}) & 0x3F) << 6 | (ord($c{3}) & 0x3F);
                
$h = "&#" . $h . ";";
                return 
$h;
            }
        }
    }
####################### FIN DE LA COMPROBACION de letras especiales
    
$content = "Mí texto con todas lás tíldes qúe se me ocura y las eÑes ñeññeñeñeñeñeeñe ñéñóñáñí";
    
$oUnicodeReplace = new unicode_replace_entities();
    
$content = $oUnicodeReplace->UTF8entities($content);

echo 
$content;
?>
Espero esto pueda ayudar a futuras generaciones y claro que este tema sea indenizado por google, porque yo no pude encontrar nade de esto en San Google.!!!
__________________
Si quieres agradecer el triangulo obscuro de la parte derecha debes presionar +.

Última edición por iovan; 21/07/2009 a las 02:13