Last active
December 20, 2016 16:20
-
-
Save vaporic/8cd620015092f64cadc6b8f93c5f4161 to your computer and use it in GitHub Desktop.
Función para remplazar caracteres especiales
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 | |
private function sanear_string($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