Return to Snippet

Revision: 46341
at May 17, 2011 19:58 by dubogii


Initial Code
Regular expression function that replaces spaces between words with hyphens.

<?php
function create_slug($string){
   $slug=preg_replace('/[^A-Za-z0-9-]+/', '-', $string);
   return $slug;
}
echo create_slug('does this thing work or not');
//returns 'does-this-thing-work-or-not'
?>

Initial URL
http://css-tricks.com/snippets/php/create-url-slug-from-post-title/

Initial Description


Initial Title
Create URL Slug from Post Title

Initial Tags
url

Initial Language
PHP