Let’s say I have an UTF-8 text like this:
âàêíóôõ <br> âàêíóôõ <br> âàêíóôõ
I want to replace <br> with <br />. Do I need to use mb_str_replace or I can use str_replace ?
Consindering < b r / > are all single byte char?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Since
str_replaceis binary-safe and UTF-8 is a bijective encoding, you can usestr_replace, even if search string or replacement contains multi-byte characters, as long as all three parameters are encoded as UTF-8.That’s why there isn’t an
mb_str_replacefunction in the first place.If your encoding is not bijective – i.e. there are multiple representations of the same string, for example
<in UTF-7, which can be expressed both as'+ADw-'and'<', you should convert all strings to the same (bijective) encoding, applystr_replace, and then convert the strings to the target encoding.