Home > code, seo > PHP: Generate Slug

PHP: Generate Slug

php_code

slug is used to represent URL’s in a friendly way. for example if we have URL

http://www.technoreaders.com/?p=1484

can be converted into

http://www.technoreaders.com/2009/11/04/php-generate-slug/

but for this you need to convert title of your page to to friendly URL. So you can use below function to generate slug of the title of your page.

function generate_slug($url)
{
$slug = strtolower($url);
$slug = preg_replace("/[^a-z0-9\s-]/", "", $slug);
$slug = trim(preg_replace("/\s+/", " ", $slug));
$slug = trim(substr($slug, 0, 45));
$slug = preg_replace("/\s/", "-", $slug);
return $slug;
}

and now to know how use this slug click here

  • Stumbleupon
  • Delicious
Share it If you like it
  • Digg
  • Reddit
  • Facebook
  • StumbleUpon
  • Twitter
  • Yahoo! Buzz
  • Google Bookmarks
  • del.icio.us
  • DZone
  • email
  • BlinkList
  • LinkedIn
  • Live
  • RSS
  • Technorati

Related Posts

  1. sunny chellan
    November 5th, 2009 at 14:27 | #1

    is it conversion of dynamic url to static url for google search engine optimization

  2. Jigish Thakar
    November 5th, 2009 at 14:29 | #2

    no, this is just a string to slug converter

  3. November 27th, 2009 at 07:41 | #3

    Does google read it in the new fashion then? Or the old fashioned way as a regular query string?

    Lemme know this, coz I need to kinda implement this on my site too
    Also, when it converts it into the new url, can I still access them via $_GET[]?

  4. November 27th, 2009 at 12:37 | #4
  1. December 4th, 2009 at 17:07 | #1