开发者

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

w开发者_JAVA技巧hy 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜