Posted By

mr_wza on 07/16/13


Tagged

slug slugify slugs


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Priestd09


slugify


 / Published in: PHP
 

string to slug

  1. function slugify($text){
  2. // replace non letter or digits by -
  3. $text = preg_replace('~[^\\pL\d]+~u', '-', $text);
  4. // trim
  5. $text = trim($text, '-');
  6. // transliterate
  7. $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
  8. // lowercase
  9. $text = strtolower($text);
  10. // remove unwanted characters
  11. $text = preg_replace('~[^-\w]+~', '', $text);
  12. if (empty($text)){
  13. return 'n-a';
  14. }
  15. return $text;
  16. }

Report this snippet  

You need to login to post a comment.