Posted By

saturnxxi on 10/27/09


Tagged

String slug


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

pster
aleksanderek


slugString


 / Published in: PHP
 

  1. static function slugString($string, $replacement = '_')
  2. {
  3. $aux = preg_quote($replacement, '/');
  4.  
  5. $map = array(
  6. '/à|á|ã|â/' = 'a',
  7. '/è|é|ê|ẽ|ë/' = 'e',
  8. '/ì|í|î/' = 'i',
  9. '/ò|ó|ô|õ|ø/' = 'o',
  10. '/ù|ú|ũ|û/' = 'u',
  11. '/ç/' = 'c',
  12. '/ñ/' = 'n',
  13. '/ä|æ/' = 'ae',
  14. '/ö/' = 'oe',
  15. '/ü/' = 'ue',
  16. '/Ä/' = 'Ae',
  17. '/Ü/' = 'Ue',
  18. '/Ö/' = 'Oe',
  19. '/ß/' = 'ss',
  20. '/[^\w\s]/' = ' ',
  21. '/\\s+/' = $replacement
  22. );
  23.  
  24. return preg_replace(array_keys($map), array_values($map), $string);
  25. }

Report this snippet  

You need to login to post a comment.