Last active
December 13, 2018 03:56
-
-
Save aswebdev/cf9c68a30e82635b42e5 to your computer and use it in GitHub Desktop.
Creates an SEO Friendly URL from a string
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
// SEO Friendly Filter Function | |
function seoUrl($string) { | |
$string = trim($string); // Trim String | |
$string = strtolower($string); //Unwanted: {UPPERCASE} ; / ? : @ & = + $ , . ! ~ * ' ( ) | |
$string = preg_replace("/[^a-z0-9_\s-]/", "", $string); //Strip any unwanted characters | |
$string = preg_replace("/[\s-]+/", " ", $string); // Clean multiple dashes or whitespaces | |
$string = preg_replace("/[\s_]/", "-", $string); //Convert whitespaces and underscore to dash | |
return $string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
another Solution using PHP's iconv with TRANSLIT:
https://blog.ueffing.net/post/2016/03/14/creating-seo-friendly-url/