Friday, May 25, 2012

PHP Convert String SEO Friendly

PHP Convert String SEO Friendly
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

1 comments:

sunset on January 24, 2019 at 9:12 AM said...

php language graphic examples
Quick PHP GD JPG Thumbnailer Script

Post a Comment

 

Blog Info

A Pakistani Website by Originative Systems

Total Pageviews

Tutorial Jinni Copyright © 2015 WoodMag is Modified by Originative Systems