识别汉字并得到汉字“拼音”简化字的语音?
是否可以
A. 找出一个字符是否是中文(简体)以及在这种情况下
B. 得到拼音吗?例子:你好=> nǐhǎo 使用java还是php?
干杯
Is it possible to
A. find out if a character is Chinese (simplified) and in that case
B. get the pinyin? example: 你好 => nǐhǎo using java or php?
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
A)
是的。以 unicode 表示的所有字符都有一个称为代码点的唯一数字索引。
如果您知道简体中文的代码点范围,并且知道如何获取给定字符的 unicode 代码点,则简单的比较将告诉您给定字符是否在简体中文范围内。
现有问题有一个在 PHP 中获取字符的 unicode 代码点的解决方案:
如何获取 utf-8 字符串中给定字符的代码点编号?
在 Java 中,静态 java.lang.Character::codePointAt() 方法将为您提供所需的内容。
B)
将简体中文字符或字符串转换为拼音很可能需要某种形式的映射,其中 unicode 代码点作为键,相应的拼音作为值。
PHP 中的示例如下: http://kingphp.com/108.html。
在 Google 上简单搜索 [java pinyin],就会发现一系列选项,其中两个是中文拼音库,位于 http://kiang.org/jordan/software/pinyinime/ 和 http://pinyin4j.sourceforge .net/。
A)
Yes. All characters represented in unicode have a unique numeric index called a codepoint.
If you know the range of codepoints for simplified Chinese and you know how to get the unicode codepoint of a given character, a simple comparison will tell you if the given character is within the simplified Chinese range.
An existing question has a solution for getting the unicode codepoint for a character in PHP:
How to get code point number for a given character in a utf-8 string?
In Java, the static java.lang.Character::codePointAt() method will give you what you need.
B)
Converting a simplified Chinese character, or string, to Pinyin would most likely require some form of map with the unicode code point as the key and the corresponding pinyin as the value.
An example of this in PHP is shown at http://kingphp.com/108.html.
A simple Google search for [java pinyin] reveals a range of options, two of which being Chinese to pinyin libraries at http://kiang.org/jordan/software/pinyinime/ and http://pinyin4j.sourceforge.net/.
有点晚了,但解决了!
如果您将其放在
http://www.example.com/foo.php
,请输入http://www.example.com/foo.php?phrase=你好< /code>,它会给你拼音。
经过测试,并且有效。
Bit late, but solved!
If you put this at
http://www.example.com/foo.php
, type inhttp://www.example.com/foo.php?phrase=你好
, and it will give you the pinyin.Tested, and works.
如果您使用 utf-8 来解释文件并调用数据库,我想一个简单的方法
应该可以解决问题。
你从哪里得到你的绳子?
If you are using utf-8 to interpret your files and calls to the DB, i guess a simple
should do the trick.
Where are you getting your string from?