Tero icon

[+] PHP Clean URL (SLUG) Generator

Tero | PRO | 05/14/19 12:58:04 PM UTC | 0 ⭐ | 389 👁️ | Never ⏰ | []
PHP |

460 B

|

None

|

0 👍

/

0 👎

// https://gist.github.com/tlongren/5527129
 
setlocale(LC_ALL, 'en_US.UTF8');
function slug_url($str, $delimiter='-') {
    $clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
    $clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
    $clean = strtolower(trim($clean, '-'));
    $clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);
    return $clean;
}
 
echo slug_url("Qu'en est-il français? Ça marche alors?");
// return: quen-est-il-francais-ca-marche-alors

Comments