I want to translate strings containing latin slavic chars like "š, đ. č, ć" to a friendly url strings. Problem is with letter đ and Đ.
protected function NameForUrl($name) {
// Replace chars Đ, đ
$string = $name;
$pattern = '/([đ])+/';
$replacement = 'dj';
$clean = preg_replace($pattern, $replacement, $string);
$clean = iconv('UTF-8', 'ASCII//TRANSLIT', $clean);
$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
$clean = strtolower(trim($clean, '-'));
$clean = preg_replace("/[\/_|+ -]+/", '-', $clean);
return $clean;
}
The problem in my code is that when preg_replace changes the 'đ' to 'dj' than iconv removes the 'j' from 'dj', and i donćt want it to be just "d". What encoding should be used for this to work, or how can i do it without iconv, as there are more stings like š,ć, č...?