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

查看:262
本文介绍了如何用PHP中的特殊字符替换它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何替换:


  • ã替换为a withe

这可能吗?我读过某个地方,我可以用基本字符的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正规化当我写它。
查看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

具体来说,该类的规范化成员:

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天全站免登陆