Don't like ads? PRO users don't see any ads ;-)

Slugify

By: Olof on May 7th, 2012  |  syntax: PHP  |  size: 0.61 KB  |  hits: 39  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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.   }