Created
December 6, 2013 13:50
-
-
Save karlgroves/7824109 to your computer and use it in GitHub Desktop.
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
/** | |
* cleans up strings so they can be used in URLS | |
* @author "Borek" - attributed to a post located at: | |
* http://drupal.org/node/63924 | |
* @param string $string the string we're cleaning | |
* @return string the input string, ready to go | |
*/ | |
function pathauto_cleanstring($string) | |
{ | |
$url = $string; | |
$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); // TRANSLIT does the whole job | |
$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
For Drupal 8 and above, you can use the following code: