I now have more than pieces of data in the database region table. now I want to convert the region names in each row of records into English (that is, Chinese pinyin) and save them at the same time, I would like to ask if there is a Chinese language library. I write a PHP program myself to convert Chinese into a spelling...
I now have more than pieces of data in the database region table. now I want to convert the region names in each row of records into English (that is, Chinese pinyin) and save them at the same time, more intuitive
I would like to ask if there is a Chinese language library. I write a PHP program myself to convert Chinese into pinyin, and then insert them in batches using SQL statements. I cannot change it in one row.
What can we do ?? Please answer
Reply content:
I now have more than pieces of data in the database region table. now I want to convert the region names in each row of records into English (that is, Chinese pinyin) and save them at the same time, more intuitive
I would like to ask if there is a Chinese language library. I write a PHP program myself to convert Chinese into pinyin, and then insert them in batches using SQL statements. I cannot change it in one row.
What can we do ?? Please answer
1, under the project need to put into the pinyin4j-2.5.0.jar, can download again online, here does not provide 2, code: import net. sourceforge. pinyin4j. pinyinHelper; import net. sourceforge. pinyin4j. format. hanyuPinyinCaseType; import net. sourceforge. pinyin4j. format. hanyuPinyinOutputFormat; import net. sourceforge. pinyin4j. format. hanyuPinyinToneType; import net. sourceforge. pinyin4j. format. exception. badHanyuPinyinOutputFormatCombination;/*** Chinese character conversion bit: Chinese pinyin, English character unchanged **/public class Cn2Spell {/*** Chinese character conversion bit: Chinese pinyin first letter, english characters remain unchanged * @ param chines Chinese characters * @ return pinyin */public static String converterToFirstSpell (String chines) {String pinyinName = ""; char [] nameChar = chines. toCharArray (); HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat (); defaultFormat. setCaseType (HanyuPinyinCaseType. LOWERCASE); defaultFormat. setToneType (HanyuPinyinToneType. WITHOUT_TONE); for (int I = 0; I <nameChar. length; I ++) {if (nameChar [I]> 128) {try {pinyinName + = PinyinHelper. toHanyuPinyinStringArray (nameChar [I], defaultFormat) [0]. charAt (0);} catch (BadHanyuPinyinOutputFormatCombination e) {e. printStackTrace () ;}} else {pinyinName + = nameChar [I] ;}return pinyinName ;}/ *** Chinese character conversion bits in Chinese pinyin, english characters remain unchanged * @ param chines Chinese characters * @ return pinyin */public static String converterToSpell (String chines) {String pinyinName = ""; char [] nameChar = chines. toCharArray (); HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat (); defaultFormat. setCaseType (HanyuPinyinCaseType. LOWERCASE); defaultFormat. setToneType (HanyuPinyinToneType. WITHOUT_TONE); for (int I = 0; I <nameChar. length; I ++) {if (nameChar [I]> 128) {try {pinyinName + = PinyinHelper. toHanyuPinyinStringArray (nameChar [I], defaultFormat) [0];} catch (BadHanyuPinyinOutputFormatCombination e) {e. printStackTrace () ;}} else {pinyinName + = nameChar [I] ;}return pinyinName;} public static void main (String [] args) {System. out. println (converterToFirstSpell ("Welcome to the Java World"); System. out. println (converterToSpell ("Welcome to the Java World "));}}
Https://github.com/overtrue/p...