This tutorial explains how to create SEO friendly URL using PHP. Friendly URLs improves your site's search engines ranking. To make a SEO friendly URL a string must be sanitized for certain things like...
- URL should be in lower case
- All spaces should be replaced with a dash or hyphen (-)
- URL must only contains letters and numbers.
- NO HTML is allowed.
I found a very quick and clean way to do this.
function Make_SEO_Friendly_URL($string)
{
// replace all non letters or digits with -
$string = preg_replace('/W+/', '-', $string);
// trim and lowercase
$string = strtolower(trim($string, '-'));
return $string;
}
Example
$string="making String SEO Friendly with PHP is easy, isnt?";
echo Make_SEO_Friendly_URL($string);
//OUTPUT
making-string-seo-friendly-with-php-is-easy-isnt