See, text is always string. I just take it from array, phrase by phrase (element by element). So, I have very short string 20-40 characters and replacing it (lat) with another (cyr). My lat string has no boundaries, I can't say "Take this line from here to here"... what I need is ellementary: take all this string and replace with this one. If you haven't cyr translation, keep it as is, don't mess it...

It must be solvable with some preg_replace(match) trick... I remember that I saw someshere attitute... as do it but in lazy mode... less aggressive...

Doing all of that with character-one-by-one would be very slow... too many lines... My sample is very clear I think...

OK.We don't need anything of that except one single line to compare execution.My code is:

CODE

$text = str_replace($lgEng,$lgSec,$val[0]);

Your code is

CODE

if($text[$i]==$find[$j]) {$text[$i]=$replace[$j];}

As text is always dirty enough with lot of slang, I need 2 passes with 2 differenet arrays: the second one is created manually and included in itself all unreplaced values (that array is not so big usually...). So, check by yourself both full codes. $lgEng is original source values and $corEng is array of values that have to be changed after first pass (remains unchanged)What I am using:

The way 'IF strings are the same do replace' works better that simple str_replace but it is additional operation and execution will be slower. DB countries has 255 elements and those text of me about 200 so 200 times we are doing 255 checking and replacement or just replacement... Because second loop is neccessary anyway, I'll stand with simple str_replace.ZIP Countrieshttp://www.laban.rs/files/Samples.zip

QUOTE(Dag @ Apr 9 2020, 08:18 PM)

Will you retry with my samples?

QUOTE(Christian J @ Apr 9 2020, 03:10 PM)

QUOTE(Christian J @ Apr 8 2020, 11:38 PM)

but for some reason it returns this:

CODE

Array( [0] => foo [1] => BAR [2] => foobar)

[1] and [2] are what I expected, but shouldn't [0] be uppercase FOO? Haven't done any PHP in a long time.

I think I found the bug in my script above. The very first $j iteration works correct:

CODE

if($text[0]==$find[0]) // foo==foo

and does change "foo" to "FOO" in $textNew[0]. But in the next $j iteration:

CODE

if($text[0]==$find[1]) // foo!=bar

the IF compares "foo" with "bar", and because that's FALSE, $textNew[0] is changed again (this time by the ELSE condition) from "FOO" to the "foo" value of $text[0]).