Tell me how you get out of the situation when you need to cut out some Cyrillic word, a letter from the text. ( str_replace does not work)
I tried the self-written functions of the mb_str_replace type - none of them gave proper results.

Example:
Suppose we have a line: $calc = "1Ρ‡20ΠΌΠΈΠ½+1Ρ‡50ΠΌΠΈΠ½";
And from it you need to remove the "min."

Or more complex cases, where there is a lot of sparse text (the initial encoding is not known in advance) and something needs to be changed in it.

2 answers 2

If the original encoding is not known in advance and, for example, you need to convert the text to a common utf-8 encoding.

 <?php $str = "1Ρ‡20ΠΌΠΈΠ½+1Ρ‡50ΠΌΠΈΠ½"; $charset = mb_detect_encoding($str); $str = iconv($charset, "UTF-8", $str); $str = str_replace("ΠΌΠΈΠ½", "", $str); echo $str; //1Ρ‡20+1Ρ‡50 ?> 

tets online: http://sandbox.onlinephpfunctions.com/code/7a1a8ab1688b23cfbe03aa40c7d722600b57789b

  • Yes, I found an error in the difference of encodings, because of this, there was a problem. - Vlad

You do something wrong, the str_replace function works successfully on this case.

 $t = str_replace("ΠΌΠΈΠ½", "", "1час5ΠΌΠΈΠ½"); echo $t; //1час5 

PHP documentation on str_replace

mixed str_replace (mixed $ search, mixed $ replace, mixed $ subject [, int & $ count])

If you want to translate a string to another encoding, use the iconv function.

 iconv("UTF-8", "ISO-8859-1", "hello");