Foros del Web » Programando para Internet » PHP »

la bendita Ñ

Estas en el tema de la bendita Ñ en el foro de PHP en Foros del Web. hola colegas como estan. me tropeze con una n con sombrero y no se que hacer, paso esa variable por post, y ya le he ...
  #1 (permalink)  
Antiguo 20/03/2009, 18:27
 
Fecha de Ingreso: marzo-2009
Mensajes: 120
Antigüedad: 15 años, 1 mes
Puntos: 1
la bendita Ñ

hola colegas como estan.

me tropeze con una n con sombrero y no se que hacer, paso esa variable por post, y ya le he pasado htmlentities y htmlspecialchars

$namen = mysql_real_escape_string(htmlentities($_POST['namen']));

pero me sigue guardando en la base de datos

niñera = niñera;
la otra me guarda niñera, -> esta es mas aceptable, pero a la hora de imprimir me imprime tal y como esta, la imprimo con nl2br.

ayuda por favor
  #2 (permalink)  
Antiguo 20/03/2009, 18:29
Avatar de pzin
Moderata 😈
 
Fecha de Ingreso: julio-2002
Ubicación: Islas Canarias
Mensajes: 10.488
Antigüedad: 21 años, 8 meses
Puntos: 2114
Respuesta: la bendita Ñ

¿Revisaste el charset del html?
  #3 (permalink)  
Antiguo 20/03/2009, 18:51
 
Fecha de Ingreso: febrero-2009
Ubicación: Cusco - Peru
Mensajes: 142
Antigüedad: 15 años, 2 meses
Puntos: 0
Respuesta: la bendita Ñ

utiliza un charset=iso-8859-1 o sino un charset=utf-8 en tus cabeceras, para queno tengas problemas.
  #4 (permalink)  
Antiguo 20/03/2009, 19:01
 
Fecha de Ingreso: diciembre-2007
Ubicación: Por ahi.
Mensajes: 13
Antigüedad: 16 años, 4 meses
Puntos: 0
Respuesta: la bendita Ñ

Fijate en el charset del HTML ponlo en utf-8 o iso-8859-1 como te dijeron y no utilices htmlentities() usa htmlspecialchars() o al menos asi solucione yo una vez que se me presento este problema.
  #5 (permalink)  
Antiguo 20/03/2009, 19:02
 
Fecha de Ingreso: junio-2007
Mensajes: 42
Antigüedad: 16 años, 10 meses
Puntos: 0
Respuesta: la bendita Ñ

usa esta funcion "utf8_encode" , convierte a formato utf8 y asi lo mandas con el mysql. es la mejor solucion a ese problema de la ñ , las otras soluciones no me convencen
  #6 (permalink)  
Antiguo 20/03/2009, 23:31
Avatar de jakoujan  
Fecha de Ingreso: septiembre-2005
Ubicación: Mexico DF
Mensajes: 26
Antigüedad: 18 años, 6 meses
Puntos: 1
Respuesta: la bendita Ñ

mira yo lo que hago al momento de guardar la info en DB la substituyo y asi me evito de problemas

te paso el codiguito que uso es un truquillo pero me va muy bien y no tengo problemas

Código PHP:
<?
// Evitamos la inyeccion SQL

// Modificamos las variables pasadas por URL
foreach( $_GET as $variable => $valor ){
$_GET $variable ] = str_replace "'" "" $_GET $variable ]);
$_GET $variable ] = str_replace "\"" "" $_GET $variable ]);
}
// Modificamos las variables de formularios
foreach( $_POST as $variable => $valor ){
$_POST $variable ] = str_replace "'" "" $_POST $variable ]);
$_POST $variable ] = str_replace "\"" "" $_POST $variable ]);
$_POST $variable ] = str_replace "á" "&aacute;" $_POST $variable ]);
$_POST $variable ] = str_replace "é" "&eacute;" $_POST $variable ]);
$_POST $variable ] = str_replace "í" "&iacute;" $_POST $variable ]);
$_POST $variable ] = str_replace "ó" "&oacute;" $_POST $variable ]);
$_POST $variable ] = str_replace "ú" "&uacute;" $_POST $variable ]);
$_POST $variable ] = str_replace "Á" "&Aacute;" $_POST $variable ]);
$_POST $variable ] = str_replace "É" "&Eacute;" $_POST $variable ]);
$_POST $variable ] = str_replace "Í" "&Iacute;" $_POST $variable ]);
$_POST $variable ] = str_replace "Ó" "&Oacute;" $_POST $variable ]);
$_POST $variable ] = str_replace "Ú" "&Uacute;" $_POST $variable ]);
$_POST $variable ] = str_replace "ñ" "&ntilde;" $_POST $variable ]);
$_POST $variable ] = str_replace "Ñ" "&Ntilde;" $_POST $variable ]);
}
?>
Bueno de hecho uso el script para evitar inyeccion SQL y me va muy bien
  #7 (permalink)  
Antiguo 20/03/2009, 23:38
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: la bendita Ñ

Hola, jakoujan.

También puedes usar htmlentities() para lograr el mismo efecto:
http://www.php.net/manual/es/function.htmlentities.php
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #8 (permalink)  
Antiguo 23/03/2009, 13:33
Avatar de jakoujan  
Fecha de Ingreso: septiembre-2005
Ubicación: Mexico DF
Mensajes: 26
Antigüedad: 18 años, 6 meses
Puntos: 1
Respuesta: la bendita Ñ

Oye david Gracias por el dato asi optimizo el funcionamiento de mi web :D

Siempre se aprende algo nuevo
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 07:05.