在 PHP 中将特殊字符(其他语言)转换为英语

发布于 2024-08-23 15:02:31 字数 54 浏览 3 评论 0原文

是否有一个函数可以将特殊字符转换为其英文等效字符。对于例如。将 é 转换为 e。 ETC...

Is there a function that coverts special characters to their english equivalents. For Eg. Convert é to e. Etc...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

無處可尋 2024-08-30 15:02:31

您想要的函数是 iconv() - 从用户注释来看,这似乎成为你想做的事:字符音译

The function you are after is iconv() - from the user notes, this seems to be what you want to do: characters transliteration

无需解释 2024-08-30 15:02:31

你应该使用这个,它会起作用:

setlocale(LC_CTYPE, 'nl_BE.utf8');
$string = iconv('UTF-8', 'ASCII//TRANSLIT', $string);

我已经测试了很多重音字符

You should use this one and it will works:

setlocale(LC_CTYPE, 'nl_BE.utf8');
$string = iconv('UTF-8', 'ASCII//TRANSLIT', $string);

I've tested it a lot of accentuated characters

剑心龙吟 2024-08-30 15:02:31

如果您不喜欢 danp 的解决方案 (iconv),您可以使用带有转换列表的 strtr这个页面有一个示例脚本(第一个Google结果)。

If you don't like danp's solution (iconv), you could use strtr with a list of conversions. This page has a sample script (first Google result).

时光匆匆的小流年 2024-08-30 15:02:31

如果 iconv() 不适合您,您可以创建一个函数来保存要交换的字符数组并传递字符串,然后将 ã 更改为这种方式。

You could make a function holding a array of chars you want exchanged and pass strings through and just change ã to a that way, if iconv() doesn´t work out for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文