Posted By

dubogii on 05/17/11


Tagged

url slug title


Versions (?)

Create URL Slug from Post Title


 / Published in: PHP
 

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

  1. Regular expression function that replaces spaces between words with hyphens.
  2.  
  3. <?php
  4. function create_slug($string){
  5. $slug=preg_replace('/[^A-Za-z0-9-]+/', '-', $string);
  6. return $slug;
  7. }
  8. echo create_slug('does this thing work or not');
  9. //returns 'does-this-thing-work-or-not'
  10. ?>

Report this snippet  

You need to login to post a comment.