PHP Clean URL function script

This is simple function to make clean urls.
It supports english and other UTF-8 language characters(like tamil, hindi, arabic..) in the urls.
Using preg_replace to remove special characters in the url considers that UTF-8 characters as special characters and replaces it.
UTF-8 characters in URLs takes more bytes so, set minimum word count for them.

Clean URL declaration follows,

$string = 'your string content';
#..check utf8 characters..
if ($this->is_utf8($$string) == '') {
    $max_word = 3;
} else {
    $max_word = 7;
$clean_url = url_cleaner($string, $max_word);
Clean URL definition follows,
function url_cleaner($str, $max_word=5, $delimiter='-') {
    $to_replace_ar = array('~','`','!','@','#','$','%','^','&','*','(',')','_','+','=','[',']','{','}','|','"','\n','\'',':',';',',','.','?','/','-','\\','<','>','’','“');
    $clean = str_replace($to_replace_ar, '',$str);
    $clean = implode(' ', array_slice(explode(' ', $clean), 0, $max_word));
    $clean = str_replace(' ', $delimiter, $clean);
    $clean = strtolower(trim($clean, '-'));

    return $clean;
UTF-8 check function definition follows,
function is_utf8($string) {
    return (utf8_encode(utf8_decode($string)) == $string);

PHP UTF8 URL Posted on 2016-05-04 08:23:31