I'm having problem with str_replace for some reason I don't understand.
The function should take all the content of a page .. skip some words, and transliterate from latin to cyrillic all the others. Here goes the code
It's obvious that I'm repeating some stupid mistake .. but I can't figure it out
The function should take all the content of a page .. skip some words, and transliterate from latin to cyrillic all the others. Here goes the code
Code:
<?php
$cyril=array("Љ","Њ","А","Б","В","Г","Д","Ђ","Е", "Ж","З","И","Ј","К","Л","М","Н","О", "П", "Р","С","Ш","Т","Ћ","У","Ф","Х","Ц","Ч", "Џ", "Ш","љ","њ","а","б","в","г","д","ђ", "е","ж", "з","и","ј","к","л", "м","н","о","п", "р","с","ш","т","ћ","у","ф","х","ц","ч", "џ","ш");
$latin=array("LJ","NJ","A","B","V","G","D","Đ","E", "Ž","Z","I","J","K","L","M","N","O", "P", "R","S","Š","T","Ć","U","F","H","C","Č", "DŽ","Š","lj","nj","a","b","v","g","d","đ", "e","ž","z", "i","j","k","l","m","n","o","p","r", "s","š","t","ć","u","f","h","c","č","dž","š");
$eng=array("engleski","example");
$content="srpski engleski primer example";
$ar=preg_split("/\b/",$content);
foreach ($ar as $word) {
$skip_this=0;
$output = $word;
for($i=0;$i<count ($eng);$i++){ #if found $eng skip transliteration
$curr_en=$eng[$i];
if ($word == $curr_en) {
$skip_this = 1;
#echo "I found word to skip: ", $output,"\n";
}
}
if ($skip_this !=1 ) {
#echo "This would be transliterated: ",$word,"\n";
for($a=0;$a<count($latin);$a++){ #transliterate latin letters to cyrillic
$current_cyr=$cyril[$a];
$current_lat=$latin[$a];
$output=str_replace($current_lat,$current_cyr,$word);
}
}
$input .= $output;
}
echo "orginal: $content transliterated: $input \n";
?>
It's obvious that I'm repeating some stupid mistake .. but I can't figure it out
Comment