Ver Mensaje Individual
  #2 (permalink)  
Antiguo 29/10/2011, 07:30
Avatar de tomark4
tomark4
 
Fecha de Ingreso: septiembre-2007
Mensajes: 154
Antigüedad: 16 años, 7 meses
Puntos: 29
Respuesta: Array no remplaza ñ :@

Prueba con esto a ver si te funciona
Código PHP:
Ver original
  1. <?php
  2. /**
  3.  * Reemplaza todos los acentos por sus equivalentes sin ellos
  4.  *
  5.  * @param $string
  6.  *  string la cadena a sanear
  7.  *
  8.  * @return $string
  9.  *  string saneada
  10.  */
  11. function reemplazar($string)
  12. {
  13.  
  14.     $string = trim($string);
  15.  
  16.     $string = str_replace(
  17.         array('á', 'à', 'ä', 'â', 'ª', 'Á', 'À', 'Â', 'Ä'),
  18.         array('a', 'a', 'a', 'a', 'a', 'A', 'A', 'A', 'A'),
  19.         $string
  20.     );
  21.  
  22.     $string = str_replace(
  23.         array('é', 'è', 'ë', 'ê', 'É', 'È', 'Ê', 'Ë'),
  24.         array('e', 'e', 'e', 'e', 'E', 'E', 'E', 'E'),
  25.         $string
  26.     );
  27.  
  28.     $string = str_replace(
  29.         array('í', 'ì', 'ï', 'î', 'Í', 'Ì', 'Ï', 'Î'),
  30.         array('i', 'i', 'i', 'i', 'I', 'I', 'I', 'I'),
  31.         $string
  32.     );
  33.  
  34.     $string = str_replace(
  35.         array('ó', 'ò', 'ö', 'ô', 'Ó', 'Ò', 'Ö', 'Ô'),
  36.         array('o', 'o', 'o', 'o', 'O', 'O', 'O', 'O'),
  37.         $string
  38.     );
  39.  
  40.     $string = str_replace(
  41.         array('ú', 'ù', 'ü', 'û', 'Ú', 'Ù', 'Û', 'Ü'),
  42.         array('u', 'u', 'u', 'u', 'U', 'U', 'U', 'U'),
  43.         $string
  44.     );
  45.  
  46.     $string = str_replace(
  47.         array('ñ', 'Ñ', 'ç', 'Ç'),
  48.         array('n', 'N', 'c', 'C',),
  49.         $string
  50.     );
  51.  
  52.     //Esta parte se encarga de eliminar cualquier caracter extraño
  53.     $string = str_replace(
  54.         array("\\", "¨", "º", "-", "~",
  55.              "#", "@", "|", "!", "\"",
  56.              "·", "$", "%", "&", "/",
  57.              "(", ")", "?", "'", "¡",
  58.              "¿", "[", "^", "`", "]",
  59.              "+", "}", "{", "¨", "´",
  60.              ">", "<", ";", ",", ":",
  61.              ".", " "),
  62.         '',
  63.         $string
  64.     );
  65.  
  66.     return $string;
  67. }
  68. echo reemplazar("hello ñs");
  69. ?>
__________________
"Todos somos ignorantes, pero no todos ignoramos las mismas cosas"

http://www.pctec21.blogspot.com
http://www.pctec21.com