There is a line: "/ catalog / mebel / divany /"
There is an array: $ trans ["mebel" => "Furniture", "divany" => "Sofas"]

It is necessary to turn from a string of translit into Cyrillic to get "/ catalog / Furniture / Sofas /"

I understand that you need to use str_replace, but it does not work out how to do this in the case of such an array. Or is there another way?
Thank.

  • Is this option "/catalog/".$trans["mebel"]."/".$trans["divany"]."/" not suitable? -
  • Most likely not or I just do not understand something. I need to explain to the script that where the word mebel is found you need to replace it with the word Furniture, and where the word divany is, you need to replace it with the word Divany. And these words are found in the text in different places. Digging in the direction of array_search () now. - Leah Hael
  • Well, you write "there is a string," and now in fact it turns out "there is a text in which the string occurs." In the question of this must be taken into account. -
  • @MasterAlex, I will consider. - Leah Hael

1 answer 1

 $str = "/catalog/mebel/divany/"; $trans = ["mebel" => "Мебель", "divany" => "Диваны"]; echo str_replace(array_keys($trans), array_values($trans), $str); 

array_keys - http://php.net/manual/ru/function.array-keys.php

array_values ​​- http://php.net/manual/ru/function.array-values.php

str_replace with arrays example - http://php.net/manual/ru/function.str-replace.php#refsect1-function.str-replace-examples

  • Thank you very much. Exactly what is needed! - Leah Hael