I have clean function for remove special caracter from string but that function also removing Turkish caracter (ı,ğ,ş,ç,ö) from string
function clean($string) {
$string = str_replace(' ', ' ', $string);
$string = preg_replace('/[^A-Za-z0-9\-]/', ' ', $string);
return preg_replace('/-+/', '-', $string);
}
How can I fix it ?
Add those characters you want to keep to preg, also add Upper cases if neededç I edited your code:
function clean($string) {
$string = str_replace(' ', ' ', $string);
$string = preg_replace('/[^A-Za-z0-9\-ığşçöüÖÇŞİıĞ]/', ' ', $string);
return preg_replace('/-+/', '-', $string);
}
Test:
$str='Merhaba=Türkiye 12345 çok çalış another one ! *, !@_';
var_dump(clean($str));
//Output: string(57) "Merhaba Türkiye 12345 çok çalış another one "
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With