[英]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 ('é' 'à' ..) ? 为什么php的str_replace和许多其他字符串函数用特殊字符(例如'é''à'..)弄乱字符串? and how to fix this problem ? 以及如何解决这个问题?
str_replace is not multi-byte (unicode) aware. str_replace不支持多字节(unicode)。 use the according mb_* functions instead 使用相应的mb_ *函数
in your place mb_ereg_replace
sounds like the right option. 在您的位置, mb_ereg_replace
听起来像是正确的选择。 you could as well just use the PCRE regex functions and specifying the X
flag 您也可以只使用PCRE regex函数并指定X
标志
PHP wasn't developed from the ground up to natively support UTF8. PHP并不是从根本上开发出来的,它本身就支持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. 代替指定字符文字,在替换中指定实体引用/十六进制代码(例如\\ x3094)并替换它,可能会很有用,我认为它得到了更一致的支持。
Though it would help seeing your direct issue at hand, with more code. 尽管它可以帮助您查看直接的问题,但需要更多代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.