PHP 中的西里尔字母音译
如何将西里尔字母转写为拉丁字母?
E.g. Главная страница -> Glavnaja stranica
这个 音译 PHP 扩展 可以很好地做到这一点,但我无法将其安装在我的服务器上。
最好有相同的实现,但使用 PHP。
How to transliterate cyrillic characters into latin letters?
E.g. Главная страница -> Glavnaja stranica
This Transliteration PHP Extension would do this very well, but I can't install it on my server.
It would be best to have the same implementation but in PHP.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(15)
@Tural Teyyuboglu
您的代码有一个问题:如果您尝试将“щеки”音译为拉丁语,然后再转回西里尔语,则会产生类似“схтеки”的内容。多字节字符必须首先出现在数组中,如下所示:
echo transliterate(null, transliterate("щеки")) == "щеки";
@Tural Teyyuboglu
Your code has a problem: if you try to transliterate for example "щеки" to latin and then back to cyrillic it will produce something like "схтеки". The multi-byte characters must appear first in the array like this:
echo transliterate(null, transliterate("щеки")) == "щеки";
最好的选择是使用 PHP Intl 扩展。
您可能需要先安装它。
这可以解决问题:
我应用了“俄语-拉丁语/BGN”,因为提问者在他的问题中使用了俄语。但是,还有使用西里尔字母书写的其他语言的选项。要查看所有这些,请执行以下操作:
The best option is using PHP Intl Extension.
You might want install it first.
This will do the trick:
I applied 'Russian-Latin/BGN' because the asker used Russian language in his question. However, there are options for other languages written in the Cyrillic script. To view all of them do this:
您应该尝试使用
iconv()
//TRANSLIT
选项。You should try
iconv()
with the//TRANSLIT
option.缺少 ё、э、ы (Э、Ы、Ё) 字母
missing ё, э, ы (Э, Ы, Ё) letters
这是我用来清理波斯尼亚语、克罗地亚语、塞尔维亚拉丁语字符的函数
Here is a function that I use for cleaning characters on Bosnian,Croatian,Serbian latin
这是我的俄语字母音译表版本。它是非官方的,但基于技术标准 GOST 7.79-2000 和 GOST 16876-71。多角色优先。
This is my version of transliteration table for russian alphabet. It's unofficial but based on technical standards GOST 7.79-2000 and GOST 16876-71. Multi-characters go first.
这个对我来说效果最好。
代码来自此页面
希望这对某人有帮助。
This one worked best for me.
Code is from this page
Hope this helps someone.
如果你想要精确到每个字母的双重转换,你需要稍微改进一下方法。
我有用于 url 的翻译,并且使用数据库搜索 url 参数。这就是为什么保持精确的字符而不用另一个字符替换对我来说非常重要。
!!!支持乌克兰符号。
if you want double conversion with accuracy to every letter, you need to improve the methods a little bit.
I have the translation used for the url, and the url parameter is searched with the database. That's why it's very important for me to keep exact characters without replacing one with the other.
!!! Support for Ukrainian symbols.
我为所有欧洲语言编写了一个完整的 utf-8 音译类。可能会有所帮助(注释是波兰语,但数量不多,所以这里有一些提示:
希望它能帮助一些人,因为实现它是一场噩梦:)
编辑:我刚刚注意到部分代码丢失了 。所以我把完整的课程放在 Pastie 上: class
I wrote a full transliteration class for all European languages for utf-8. May help (comments are in polish but there isn't a lot of them so here's a few hints:
Hope it will help a few people 'cause implementing it was a nightmare :)
Edit: I just noticed that part of the code is missing so I've put the full class on Pastie: class
尊重 Yandex 音译规则 (http://www.translityandex.ru/) 并转换大写:
Respecting the Yandex transliteration rules (http://www.translityandex.ru/) and converting the upper case:
由于以上所有内容都不完整,这是我的版本:
我更喜欢 ё = e、ъ = i、ы = y 和 э = e,因为我正在使用这种方式。
Since all above are incomplete, here is my version:
I prefered ё = e, ъ = i, ы = y and э = e because I am using that way.
对我来说最好的解决方案是使用
for me the best solution was to use
如果有人需要从西里尔语到拉丁语的官方乌克兰语音译,您可以使用此代码。它基于此处的官方政府音译。
请注意,某些字母(例如“ь”)不会返回任何内容。这意味着如果您需要从西里尔文到拉丁文的官方乌克兰语音译,您可以使用此代码,但如果您需要将其从拉丁文转换为西里尔文,则返回正确的文本可能会出现问题。
我希望它有用。
If someone needs OFFICIAL Ukrainian transliteration from Cyrillic to Latin you can use this code. It's based on the official government transliteration located here.
Pay attention that some letters (like "ь") return nothing. That means you can use this code if you need OFFICIAL Ukrainian transliteration from Cyrillic to Latin, but it can be problematic to return correct text if you need to convert it from Latin to Cyrillic.
I hope it can be useful.
尝试以下代码
Try following code