如何用它们在 PHP 中基于的特殊字符替换特殊字符?
如何更换:
- ã"与a"
- é"与e"
在 PHP 中?这可能吗?我在某处读到过,我可以用基本字符的 ascii 值和重音的 ascii 值进行一些数学计算,但我现在找不到任何参考资料.
in PHP? Is this possible? I've read somewhere I could do some math with the ascii value of the base character and the ascii value of the accent, but I can't find any references now.
推荐答案
此答案不正确.我写的时候不理解 Unicode Normalization.看 francadaval 的评论和链接
查看 Normalizer 类来执行此操作.文档很好,所以我只是链接它而不是在这里重复:
Check out the Normalizer class to do this. The documentation is good, so I'll just link it instead of repeating things here:
http://www.php.net/manual/en/class.normalizer.php
具体来说,该类的 normalize 成员:
Specifically, the normalize member of that class:
http://www.php.net/manual/en/normalizer.normalize.php
请注意,Unicode 规范化有多种形式,您似乎想要规范化形式 KD (NFKD) 兼容性分解,但您应该阅读文档以确保.
Note that Unicode normalization has several forms, and you seem to want Normalization Form KD (NFKD) Compatibility Decomposition, though you should read the documentation to make sure.
您不应该尝试为此推出自己的函数:可能出错的事情太多了,使用提供的函数是一个更好的主意.
You shouldn't try to roll your own function for this: There's way too many things that can go wrong, and using the provided function is a much better idea.
相关文章