简体   繁体   中英

why php's str_replace mess up the strings with special chars

why php's str_replace and many other string functions mess up the strings with special chars such ('é' 'à' ..) ? and how to fix this problem ?

str_replace is not multi-byte (unicode) aware. use the according mb_* functions instead

in your place mb_ereg_replace sounds like the right option. you could as well just use the PCRE regex functions and specifying the X flag

PHP wasn't developed from the ground up to natively support UTF8. It may be useful to instead of specify the character literal, specify the entity reference / hex code of that in your replacement, eg \\x3094 and replace that, I think it's more consistently supported.

Though it would help seeing your direct issue at hand, with more code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM