Tero

[+] PHP Clean URL (SLUG) Generator

May 14th, 2019
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.46 KB | None | 0 0
  1. // https://gist.github.com/tlongren/5527129
  2.  
  3. setlocale(LC_ALL, 'en_US.UTF8');
  4. function slug_url($str, $delimiter='-') {
  5.     $clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
  6.     $clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
  7.     $clean = strtolower(trim($clean, '-'));
  8.     $clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);
  9.     return $clean;
  10. }
  11.  
  12. echo slug_url("Qu'en est-il français? Ça marche alors?");
  13. // return: quen-est-il-francais-ca-marche-alors
Advertisement
Add Comment
Please, Sign In to add comment