Skip to content

Instantly share code, notes, and snippets.

@mig1098
Last active October 21, 2015 16:23
Show Gist options
  • Save mig1098/505467fc555c94c372cd to your computer and use it in GitHub Desktop.
Save mig1098/505467fc555c94c372cd to your computer and use it in GitHub Desktop.
function cleanString($text) {
$utf8 = array(
'/[áàâãªä]/u' => 'a',
'/[ÁÀÂÃÄ]/u' => 'A',
'/[ÍÌÎÏ]/u' => 'I',
'/[íìîï]/u' => 'i',
'/[éèêë]/u' => 'e',
'/[ÉÈÊË]/u' => 'E',
'/[óòôõºö]/u' => 'o',
'/[ÓÒÔÕÖ]/u' => 'O',
'/[úùûü]/u' => 'u',
'/[ÚÙÛÜ]/u' => 'U',
'/ç/' => 'c',
'/Ç/' => 'C',
'/ñ/' => 'n',
'/Ñ/' => 'N',
'/–/' => '-', // UTF-8 hyphen to "normal" hyphen
'/[’‘‹›‚]/u' => ' ', // Literally a single quote
'/[“”«»„]/u' => ' ', // Double quote
'/ /' => ' ', // nonbreaking space (equiv. to 0x160)
'/\r?\n/u' => '',
'/u201/m' => '"',
'/u00a0/m' => '',
'/ /' => ' '
);
return preg_replace(array_keys($utf8), array_values($utf8), $text);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment