Slug Url土耳其人物

I have one question. I am using slug url function for my SEO friendly url but my function not posted turkish character.

function url_slug($str)
{   
    $str = mb_strtolower( trim( $str ), 'UTF-8' );
    $str = preg_replace('/[^a-zA-Z0-9]/i',' ', $str);
    $str = trim($str);
    $str = preg_replace('/\s+/', '-', $str);
    return $str;
}

for example when i post this title: şekerli bir öğütücü çok ışıklı bir bahçe

Url shows me : ekerli-bir-t-c-ok-kl-bir-bah-e

What can i do here? Anyone can help me here ?

Use the u modifier in your regex to make it work with UTF-8. Change the following line:

$str = preg_replace('/[^a-zA-Z0-9]/i',' ', $str);

to this:

$str = preg_replace('/[[:^alnum:]]/iu', ' ', $str);

Change your second line to this

$str = preg_replace('/[^a-zA-Z0-9\x{00E7}\x{011F}\x{0131}\x{015F}\x{00F6}\x{00FC}\x{00C7}\x{011E}\x{0130}\x{015E}\x{00D6}\x{00DC}]/u', ' ', $str);

As you can see the new expression extends the range for the Turkish characters below

ç \x{00E7}
ğ \x{011F}
ı \x{0131}
ş \x{015F}
ö \x{00F6}
ü \x{00FC}
Ç \x{00C7}
Ğ \x{011E}
İ \x{0130}
Ş \x{015E}
Ö \x{00D6}
Ü \x{00DC}

Expected output:

sekerli-bir-ögütücü-çok-isikli-bir-bahçe