Posted By

liamchapman on 11/02/10


Tagged

php urls


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

mikael12


Slugify function (Clean URLS)


 / Published in: PHP
 

Quick and simple script to make clean urls. Works in combination with Apache mod_rewrites :-)

  1. <?php
  2.  
  3. function slugify($str, $replace="-")
  4. {
  5. // replace all non letters or digits by $replace
  6. $str = preg_replace('/\W+/', $replace, $str);
  7.  
  8. // trim and lowercase
  9. $str = strtolower(trim($str, $replace));
  10.  
  11. return $str;
  12. }
  13.  
  14. ?>

Report this snippet  

You need to login to post a comment.