Slugify function (Clean URLS)


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.