Last active
July 31, 2016 05:14
-
-
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
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
/** | |
* 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