Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. <?php
  2. static public function slugify($text)
  3. {
  4. // replace non letter or digits by -
  5. $text = preg_replace('~[^\pL\d]+~u', '-', $text);
  6.  
  7. // transliterate
  8. $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
  9.  
  10. // remove unwanted characters
  11. $text = preg_replace('~[^-\w]+~', '', $text);
  12.  
  13. // trim
  14. $text = trim($text, '-');
  15.  
  16. // remove duplicate -
  17. $text = preg_replace('~-+~', '-', $text);
  18.  
  19. // lowercase
  20. $text = strtolower($text);
  21.  
  22. if (empty($text)) {
  23. return 'n-a';
  24. }
  25.  
  26. return $text;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement