Posted By

mscribellito on 12/07/10


Tagged


Versions (?)

String to Slug


 / Published in: PHP
 

  1. function slug($str, $sep = '-') {
  2.  
  3. $str = trim(strtolower($str));
  4. $str = preg_replace('/[^a-z0-9\s+]/', '', $str);
  5. $str = preg_replace('/\s+/', $sep, $str);
  6.  
  7. return $str;
  8. }

Report this snippet  

You need to login to post a comment.