problem with str_replace
Posted: Sun Feb 17, 2008 9:23 am
I have trouble with str_replace for some reason I don't understand.
The funcion 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 doesn't change any of the letters .. It should transliterate from latin to cyrillic, word by word. But when it comes to str_replace it doesn't replace any of the letters for some reason.
It's obvious that I'm repeating some stupid mistake .. but I can't figure it out
The funcion 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: Select all
<?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