Created
February 28, 2014 22:10
-
-
Save luiscelismx/9281064 to your computer and use it in GitHub Desktop.
Función en PHP para eliminar los acentos en una cadena de texto.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| -- ============================================= | |
| -- Author: Luis Antonio Celis Molina | |
| -- Create date: 20/03/2010 | |
| -- Description: Limpia cadena y regresa sin acentos | |
| -- Parametros: @text string con la variable a limpiar | |
| -- ============================================= | |
| */ | |
| function elimina_acentos($text) | |
| { | |
| $text = htmlentities($text, ENT_QUOTES, 'UTF-8'); | |
| $text = strtolower($text); | |
| $patron = array ( | |
| // Espacios, puntos y comas por guion | |
| //'/[\., ]+/' => ' ', | |
| // Vocales | |
| '/\+/' => '', | |
| '/à/' => 'a', | |
| '/è/' => 'e', | |
| '/ì/' => 'i', | |
| '/ò/' => 'o', | |
| '/ù/' => 'u', | |
| '/á/' => 'a', | |
| '/é/' => 'e', | |
| '/í/' => 'i', | |
| '/ó/' => 'o', | |
| '/ú/' => 'u', | |
| '/â/' => 'a', | |
| '/ê/' => 'e', | |
| '/î/' => 'i', | |
| '/ô/' => 'o', | |
| '/û/' => 'u', | |
| '/ã/' => 'a', | |
| '/&etilde;/' => 'e', | |
| '/ĩ/' => 'i', | |
| '/õ/' => 'o', | |
| '/ũ/' => 'u', | |
| '/ä/' => 'a', | |
| '/ë/' => 'e', | |
| '/ï/' => 'i', | |
| '/ö/' => 'o', | |
| '/ü/' => 'u', | |
| '/ä/' => 'a', | |
| '/ë/' => 'e', | |
| '/ï/' => 'i', | |
| '/ö/' => 'o', | |
| '/ü/' => 'u', | |
| // Otras letras y caracteres especiales | |
| '/å/' => 'a', | |
| '/ñ/' => 'n', | |
| // Agregar aqui mas caracteres si es necesario | |
| ); | |
| $text = preg_replace(array_keys($patron),array_values($patron),$text); | |
| return $text; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Muy buena función, solo un inconveniente, la siguiente sección esta duplicada, de la linea 46 a la 56:
'/ä/' => 'a',
'/ë/' => 'e',
'/ï/' => 'i',
'/ö/' => 'o',
'/ü/' => 'u',