Created
October 9, 2015 17:56
-
-
Save jemekite/0774eac1cf816780ada9 to your computer and use it in GitHub Desktop.
Clean URL
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 cleanURL($string) | |
{ | |
$url = str_replace("'", '', $string); | |
$url = str_replace('%20', ' ', $url); | |
$url = preg_replace('~[^\\pL0-9_]+~u', '-', $url); // substitutes anything but letters, numbers and '_' with separator | |
$url = trim($url, "-"); | |
$url = iconv("utf-8", "us-ascii//TRANSLIT", $url); // you may opt for your own custom character map for encoding. | |
$url = strtolower($url); | |
$url = preg_replace('~[^-a-z0-9_]+~', '', $url); // keep only letters, numbers, '_' and separator | |
return $url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment