Skip to content

Instantly share code, notes, and snippets.

@daronwolff
Last active July 31, 2016 05:14
Show Gist options
  • Save daronwolff/640b9cd7fa521219a5b8e9965659a347 to your computer and use it in GitHub Desktop.
Save daronwolff/640b9cd7fa521219a5b8e9965659a347 to your computer and use it in GitHub Desktop.
PHP, This function removes the accents, white-spaces and symbols from characters in a string. Can be used to clear the strings on usernames, filenames
/**
* Function clear_string
*
* Function used to user strings as usernames, filenames
* This function removes the accents, white-spaces and symbols from characters in a string
*/
if (! function_exists('clear_string'))
{
function clear_string($str = '')
{
$str = strtr(utf8_decode($str), utf8_decode('àáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ'), 'aaaaaceeeeiiiinooooouuuuyyAAAAACEEEEIIIINOOOOOUUUUY');
$str = strtolower(trim(preg_replace("![^a-z0-9_]+!i", "", $str)));
return $str;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment