如何用它们在 PHP 中基于的特殊字符替换特殊字符? [英] how to replace special characters with the ones they're based on in PHP?

查看:31
本文介绍了如何用它们在 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.

这篇关于如何用它们在 PHP 中基于的特殊字符替换特殊字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆