PHP 将变音符号从例如“ue”转换为至““xFC”

发布于 2024-11-25 13:28:58 字数 159 浏览 0 评论 0原文

有没有办法将变音符号从 ae、Ae、oe、Oe、ue、Ue 和 ss 表示形式转换回原始变音符号?重要的是,拼写必须遵守“teuer”!例如,“teür”中的术语“teuer”不得更改。谢谢!

Is there a way to convert umlauts from the representations ae, Ae, oe, Oe, ue, Ue and ss, back to the original umlauts? Important is that the spelling is observed like "teuer"! For example, the term "teuer" must not be changed in "teür". Thanks!

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

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

发布评论

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

评论(3

债姬 2024-12-02 13:28:58
iconv("utf-8","ascii//TRANSLIT",$input);

扩展示例

echo strtr(utf8_decode($input), 
           utf8_decode('ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ'),
           'SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy');

参考这个问题

iconv("utf-8","ascii//TRANSLIT",$input);

Extended example

OR

echo strtr(utf8_decode($input), 
           utf8_decode('ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ'),
           'SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy');

Refer this question.

别在捏我脸啦 2024-12-02 13:28:58

我建议您转换“ue”、“oe”等出现的每个排列。
对于每个排列,我的意思是如果出现 3 次,则首先仅替换第一个,然后仅替换第二个,然后仅替换第三个,然后是第一个和第二个,依此类推。

接下来,检查结果是否包含在标准拼写检查字典中。这样您就不必为异常创建自己的字典。

例如,可以在 ftp://ftp.ox 上找到单词列表.ac.uk/pub/wordlists/german/words.german.Z

I suggest you convert each permutation of occurences of "ue", "oe" and so on.
By each permutation I mean if there are 3 occurences first replace only the first, then only the second, then only the third, then first and second and so on.

Next, check if the results are contained in a standard spellchecking dictionary. By this you do not have to create your own dictionary for exceptions.

A wordlist can be found for example on ftp://ftp.ox.ac.uk/pub/wordlists/german/words.german.Z

忆沫 2024-12-02 13:28:58

要做到这一点将非常棘手。当然没有任何内置函数可以做到这一点。

我见过的大多数此类事情的示例都以相反的方向工作(即采用带有重音字符的字符串并将其替换为其 ASCII 等效项)。在我见过的地方,总是提供字符及其等效项的映射,并扫描字符串进行替换。

strtr() 函数的 PHP 手册页对于您需要做的事情有一些很好的例子,但是您避免特定异常的要求将使整个过程变得非常复杂。

This is going to be pretty tricky to get right. There certainly isn't any built-in function to do it.

Most of the examples I've seen for this kind of thing work in the opposite direction (ie taking a string with accented characters and replacing them with their ASCII equivalents). Where I have seen it done, it's always been a case of providing a map of characters and their equivalents, and scanning the string doing replacements.

The PHP manual page for the strtr() function has some good examples on the kind of thing you'd need to do, but your requirements to avoid specific exceptions is going to complicate the whole process enormously.

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