Skip to content

Instantly share code, notes, and snippets.

@vaporic
Last active December 20, 2016 16:20
Show Gist options
  • Save vaporic/8cd620015092f64cadc6b8f93c5f4161 to your computer and use it in GitHub Desktop.
Save vaporic/8cd620015092f64cadc6b8f93c5f4161 to your computer and use it in GitHub Desktop.
Función para remplazar caracteres especiales
<?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
'/\+/' => '',
'/&agrave;/' => 'a',
'/&egrave;/' => 'e',
'/&igrave;/' => 'i',
'/&ograve;/' => 'o',
'/&ugrave;/' => 'u',
'/&aacute;/' => 'a',
'/&eacute;/' => 'e',
'/&iacute;/' => 'i',
'/&oacute;/' => 'o',
'/&uacute;/' => 'u',
'/&acirc;/' => 'a',
'/&ecirc;/' => 'e',
'/&icirc;/' => 'i',
'/&ocirc;/' => 'o',
'/&ucirc;/' => 'u',
'/&atilde;/' => 'a',
'/&etilde;/' => 'e',
'/&itilde;/' => 'i',
'/&otilde;/' => 'o',
'/&utilde;/' => 'u',
'/&auml;/' => 'a',
'/&euml;/' => 'e',
'/&iuml;/' => 'i',
'/&ouml;/' => 'o',
'/&uuml;/' => 'u',
'/&auml;/' => 'a',
'/&euml;/' => 'e',
'/&iuml;/' => 'i',
'/&ouml;/' => 'o',
'/&uuml;/' => 'u',
// Otras letras y caracteres especiales
'/&aring;/' => 'a',
'/&ntilde;/' => '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