Posted By

valenzine on 09/20/12


Tagged

url php slug sanitize permalink


Versions (?)

SimpleText


 / Published in: PHP
 

URL: http://stackoverflow.com/a/10997500

Taken from http://stackoverflow.com/a/10997500

  1. function simpleText($s) {
  2. $rpl = array(
  3. "À" => 'A', "Á" => 'A', "Â" => 'A', "Ã" => 'A', "Ä" => 'A', "Å" => 'A',
  4. "à" => 'a', "á" => 'a', "â" => 'a', "ã" => 'a', "ä" => 'a', "å" => 'a',
  5. "Ò" => 'O', "Ó" => 'O', "Ô" => 'O', "Õ" => 'O', "Ö" => 'O', "Ø" => 'O',
  6. "ò" => 'o', "ó" => 'o', "ô" => 'o', "õ" => 'o', "ö" => 'o', "ø" => 'o',
  7. "È" => 'E', "É" => 'E', "Ê" => 'E', "Ë" => 'E',
  8. "è" => 'e', "é" => 'e', "ê" => 'e', "ë" => 'e',
  9. "Ç" => 'C',
  10. "ç" => 'c',
  11. "Ì" => 'I', "Í" => 'I', "Î" => 'I', "Ï" => 'I',
  12. "ì" => 'i', "í" => 'i', "î" => 'i', "ï" => 'i',
  13. "Ù" => 'U', "Ú" => 'U', "Û" => 'U', "Ü" => 'U',
  14. "ù" => 'u', "ú" => 'u', "û" => 'u', "ü" => 'u',
  15. "Ÿ" => 'Y',
  16. "ÿ" => 'y',
  17. "Ñ" => 'N',
  18. "ñ" => 'n'
  19. );
  20.  
  21. $s = preg_replace('`\s+`', '_', strtr($s, $rpl));
  22. $s = strtolower(preg_replace('`_+`', '_', preg_replace('`[^-_A-Za-z0-9]`', '', $s)));
  23. return trim($s, '_');
  24. }

Report this snippet  

You need to login to post a comment.