Advertisement
Olof

Slugify

May 7th, 2012
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.61 KB | None | 0 0
  1. function slugify($string){
  2.     $string = strtolower(trim($string));
  3.     $string = str_replace(array('å', 'ä', 'ö'), array('a', 'a', 'o'), $string);
  4.     $string = preg_replace('/[^a-z0-9-]/', '-', $string);
  5.     $string = preg_replace('/-+/', "-", $string);
  6.     return $string;
  7. }
  8.  
  9. UTF-8
  10.  function slugify($string){
  11.             $string = mb_strtolower(trim($string),'UTF-8');
  12.             $string = str_replace(array('å', 'ä', 'ö'), array('a', 'a', 'o'), $string);
  13.             $string = preg_replace('/[^a-z0-9-]/', '-', $string);
  14.             $string = preg_replace('/-+/', "-", $string);
  15.             return $string;
  16.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement