PHP under the conversion of Chinese characters to Pinyin code 1th/2 page _php tips

Source: Internet
Author: User
Tags ord
Copy Code code as follows:

<?php
$d = Array (
Array ("A",-20319),
Array ("AI",-20317),
Array ("an",-20304),
Array ("Ang",-20295),
Array ("AO",-20292),
Array ("BA",-20283),
Array ("Bai",-20265),
Array ("Ban",-20257),
Array ("Bang",-20242),
Array ("Bao",-20230),
Array ("Bei",-20051),
Array ("Ben",-20036),
Array ("Beng",-20032),
Array ("BI",-20026),
Array ("Bian",-20002),
Array ("Biao",-19990),
Array ("Bie",-19986),
Array ("Bin",-19982),
Array ("Bing",-19976),
Array ("Bo",-19805),
Array ("Bu",-19784),
Array ("Ca",-19775),
Array ("Cai",-19774),
Array ("Can",-19763),
Array ("Cang",-19756),
Array ("Cao",-19751),
Array ("Ce",-19746),
Array ("CEng",-19741),
Array ("Cha",-19739),
Array ("Chai",-19728),
Array ("Chan",-19725),
Array ("Chang",-19715),
Array ("Chao",-19540),
Array ("Che",-19531),
Array ("Chen",-19525),
Array ("Cheng",-19515),
Array ("Chi",-19500),
Array ("Chong",-19484),
Array ("Chou",-19479),
Array ("Chu",-19467),
Array ("Chuai",-19289),
Array ("Chuan",-19288),
Array ("Chuang",-19281),
Array ("Chui",-19275),
Array ("Chun",-19270),
Array ("Chuo",-19263),
Array ("CI",-19261),
Array ("Cong",-19249),
Array ("Cou",-19243),
Array ("CU",-19242),
Array ("Cuan",-19238),
Array ("Cui",-19235),
Array ("Cun",-19227),
Array ("CuO",-19224),
Array ("Da",-19218),
Array ("Dai",-19212),
Array ("Dan",-19038),
Array ("Dang",-19023),
Array ("DAO",-19018),
Array ("De",-19006),
Array ("Deng",-19003),
Array ("Di",-18996),
Array ("Dian",-18977),
Array ("Diao",-18961),
Array ("Die",-18952),
Array ("Ding",-18783),
Array ("Diu",-18774),
Array ("Dong",-18773),
Array ("Dou",-18763),
Array ("Du",-18756),
Array ("Duan",-18741),
Array ("DUI",-18735),
Array ("Dun",-18731),
Array ("Duo",-18722),
Array ("E",-18710),
Array ("en",-18697),
Array ("ER",-18696),
Array ("FA",-18526),
Array ("Fan",-18518),
Array ("Fang",-18501),
Array ("Fei",-18490),
Array ("Fen",-18478),
Array ("Feng",-18463),
Array ("fo",-18448),
Array ("Fou",-18447),
Array ("Fu",-18446),
Array ("GA",-18239),
Array ("Gai",-18237),
Array ("Gan",-18231),
Array ("Gang",-18220),
Array ("Gao",-18211),
Array ("GE",-18201),
Array ("GEi",-18184),
Array ("Gen",-18183),
Array ("Geng",-18181),
Array ("Gong",-18012),
Array ("Gou",-17997),
Array ("Gu",-17988),
Array ("Gua",-17970),
Array ("Guai",-17964),
Array ("Guan",-17961),
Array ("Guang",-17950),
Array ("GUI",-17947),
Array ("Gun",-17931),
Array ("Guo",-17928),
Array ("Ha",-17922),
Array ("Hai",-17759),
Array ("Han",-17752),
Array ("Hang",-17733),
Array ("Hao",-17730),
Array ("he",-17721),
Array ("Hei",-17703),
Array ("Hen",-17701),
Array ("Heng",-17697),
Array ("The",-17692),
Array ("Hou",-17683),
Array ("Hu",-17676),
Array ("Hua",-17496),
Array ("Huai",-17487),
Array ("Huan",-17482),
Array ("Huang",-17468),
Array ("Hui",-17454),
Array ("Hun",-17433),
Array ("Huo",-17427),
Array ("Ji",-17417),
Array ("Jia",-17202),
Array ("Jian",-17185),
Array ("Jiang",-16983),
Array ("Jiao",-16970),
Array ("Jie",-16942),
Array ("Jin",-16915),
Array ("Jing",-16733),
Array ("Jiong",-16708),
Array ("JIU",-16706),
Array ("Ju",-16689),
Array ("Juan",-16664),
Array ("Jue",-16657),
Array ("June",-16647),
Array ("Ka",-16474),
Array ("Kai",-16470),
Array ("Kan",-16465),
Array ("Kang",-16459),
Array ("Kao",-16452),
Array ("Ke",-16448),
Array ("Ken",-16433),
Array ("Keng",-16429),
Array ("Kong",-16427),
Array ("Kou",-16423),
Array ("Ku",-16419),
Array ("Kua",-16412),
Array ("Kuai",-16407),
Array ("Kuan",-16403),
Array ("Kuang",-16401),
Array ("Kui",-16393),
Array ("Kun",-16220),
Array ("Kuo",-16216),
Array ("La",-16212),
Array ("Lai",-16205),
Array ("LAN",-16202),
Array ("Lang",-16187),
Array ("Lao",-16180),
Array ("Le",-16171),
Array ("Lei",-16169),
Array ("Leng",-16158),
Array ("Li",-16155),
Array ("Lia",-15959),
Array ("Lian",-15958),
Array ("Liang",-15944),
Array ("Liao",-15933),
Array ("Lie",-15920),
Array ("Lin",-15915),
Array ("Ling",-15903),
Array ("Liu",-15889),
Array ("Long",-15878),
Array ("Lou",-15707),
Array ("Lu",-15701),
Array ("LV",-15681),
Array ("Luan",-15667),
Array ("Lue",-15661),
Array ("LUN",-15659),
Array ("Luo",-15652),
Array ("Ma",-15640),
Array ("Mai",-15631),
Array ("Man",-15625),
Array ("Mang",-15454),
Array ("Mao",-15448),
Array ("Me",-15436),
Array ("Mei",-15435),
Array ("Men",-15419),
Array ("Meng",-15416),
Array ("Mi",-15408),
Array ("Mian",-15394),
Array ("Miao",-15385),
Array ("Mie",-15377),
Array ("Min",-15375),
Array ("Ming",-15369),
Array ("Miu",-15363),
Array ("Mo",-15362),
Array ("MoU",-15183),
Array ("Mu",-15180),
Array ("NA",-15165),
Array ("Nai",-15158),
Array ("Nan",-15153),
Array ("Nang",-15150),
Array ("Nao",-15149),
Array ("NE",-15144),
Array ("Nei",-15143),
Array ("nen",-15141),
Array ("Neng",-15140),
Array ("Ni",-15139),
Array ("Nian",-15128),
Array ("Niang",-15121),
Array ("Niao",-15119),
Array ("Nie",-15117),
Array ("Nin",-15110),
Array ("Ning",-15109),
Array ("Niu",-14941),
Array ("Nong",-14937),
Array ("Nu",-14933),
Array ("NV",-14930),
Array ("Nuan",-14929),
Array ("Nue",-14928),
Array ("Nuo",-14926),
Array ("O",-14922),
Array ("ou",-14921),
Array ("Pa",-14914),
Array ("Pai",-14908),
Array ("Pan",-14902),
Array ("Pang",-14894),
Array ("Pao",-14889),
Array ("Pei",-14882),
Array ("Pen",-14873),
Array ("Peng",-14871),
Array ("PI",-14857),
Array ("Pian",-14678),
Array ("Piao",-14674),
Array ("Pie",-14670),
Array ("Pin",-14668),
Array ("ping",-14663),
Array ("Po",-14654),
Array ("Pu",-14645),
Array ("Qi",-14630),
Array ("QIA",-14594),
Array ("Qian",-14429),
Array ("Qiang",-14407),
Array ("Qiao",-14399),
Array ("Qie",-14384),
Array ("Qin",-14379),
Array ("Qing",-14368),
Array ("Qiong",-14355),
Array ("Qiu",-14353),
Array ("Qu",-14345),
Array ("Quan",-14170),
Array ("que",-14159),
Array ("Qun",-14151),
Array ("ran",-14149),
Array ("Rang",-14145),
Array ("Rao",-14140),
Array ("Re",-14137),
Array ("Ren",-14135),
Array ("Reng",-14125),
Array ("Ri",-14123),
Array ("Rong",-14122),
Array ("Rou",-14112),
Array ("Ru",-14109),
Array ("Ruan",-14099),
Array ("Rui",-14097),
Array ("Run",-14094),
Array ("Ruo",-14092),
Array ("SA",-14090),
Array ("Sai",-14087),
Array ("San",-14083),
Array ("sang",-13917),
Array ("Sao",-13914),
Array ("se",-13910),
Array ("Sen",-13907),
Array ("Seng",-13906),
Array ("Sha",-13905),
Array ("Shai",-13896),
Array ("Shan",-13894),
Array ("Shang",-13878),
Array ("Shao",-13870),
Array ("She",-13859),
Array ("Shen",-13847),
Array ("Sheng",-13831),
Array ("Shi",-13658),
Array ("Shou",-13611),
Array ("Shu",-13601),
Array ("Shua",-13406),
Array ("Shuai",-13404),
Array ("Shuan",-13400),
Array ("Shuang",-13398),
Array ("Shui",-13395),
Array ("Shun",-13391),
Array ("Shuo",-13387),
Array ("Si",-13383),
Array ("Song",-13367),
Array ("Sou",-13359),
Array ("Su",-13356),
Array ("Suan",-13343),
Array ("Sui",-13340),
Array ("Sun",-13329),
Array ("suo",-13326),
Array ("Ta",-13318),
Array ("Tai",-13147),
Array ("Tan",-13138),
Array ("Tang",-13120),
Array ("Tao",-13107),
Array ("TE",-13096),
Array ("Teng",-13095),
Array ("Ti",-13091),
Array ("Tian",-13076),
Array ("Tiao",-13068),
Array ("Tie",-13063),
Array ("Ting",-13060),
Array ("Tong",-12888),
Array ("Tou",-12875),
Array ("Tu",-12871),
Array ("Tuan",-12860),
Array ("Tui",-12858),
Array ("Tun",-12852),
Array ("Tuo",-12849),
Array ("WA",-12838),
Array ("Wai",-12831),
Array ("WAN",-12829),
Array ("Wang",-12812),
Array ("Wei",-12802),
Array ("Wen",-12607),
Array ("Weng",-12597),
Array ("Wo",-12594),
Array ("WU",-12585),
Array ("Xi",-12556),
Array ("Xia",-12359),
Array ("Xian",-12346),
Array ("Xiang",-12320),
Array ("Xiao",-12300),
Array ("Xie",-12120),
Array ("Xin",-12099),
Array ("Xing",-12089),
Array ("Xiong",-12074),
Array ("Xiu",-12067),
Array ("Xu",-12058),
Array ("Xuan",-12039),
Array ("Xue",-11867),
Array ("Xun",-11861),
Array ("Ya",-11847),
Array ("Yan",-11831),
Array ("Yang",-11798),
Array ("Yao",-11781),
Array ("Ye",-11604),
Array ("Yi",-11589),
Array ("Yin",-11536),
Array ("Ying",-11358),
Array ("Yo",-11340),
Array ("Yong",-11339),
Array ("You",-11324),
Array ("Yu",-11303),
Array ("Yuan",-11097),
Array ("Yue",-11077),
Array ("Yun",-11067),
Array ("Za",-11055),
Array ("Zai",-11052),
Array ("Zan",-11045),
Array ("Zang",-11041),
Array ("Zao",-11038),
Array ("Ze",-11024),
Array ("Zei",-11020),
Array ("Zen",-11019),
Array ("Zeng",-11018),
Array ("Zha",-11014),
Array ("Zhai",-10838),
Array ("Zhan",-10832),
Array ("Zhang",-10815),
Array ("Zhao",-10800),
Array ("Zhe",-10790),
Array ("Zhen",-10780),
Array ("Zheng",-10764),
Array ("Zhi",-10587),
Array ("Zhong",-10544),
Array ("Zhou",-10533),
Array ("Zhu",-10519),
Array ("Zhua",-10331),
Array ("Zhuai",-10329),
Array ("Zhuan",-10328),
Array ("Zhuang",-10322),
Array ("Zhui",-10315),
Array ("Zhun",-10309),
Array ("Zhuo",-10307),
Array ("Zi",-10296),
Array ("Zong",-10281),
Array ("Zou",-10274),
Array ("Zu",-10270),
Array ("Zuan",-10262),
Array ("Zui",-10260),
Array ("Zun",-10256),
Array ("Zuo",-10254)
);

function g ($num) {
Global $d;
if ($num >0&& $num <160) {
return Chr ($num);
}
ElseIf ($num <-20319| | $num >-10247) {
Return "";
}else{
For ($i =count ($d)-1; $i >=0; $i-) {
if ($d [$i][1]<= $num) break;
}
return $d [$i][0];
}
}

Function C ($str) {
$ret = "";
for ($i =0; $i <strlen ($STR); $i + +) {
$p =ord (substr ($str, $i, 1));
if ($p >160) {
$q =ord (substr ($str, + + $i, 1));
$p = $p *256+ $q-65536;
}
$ret. =g ($p);
}
return $ret;
}

Echo (substr (C ("script"), 0, 1));
?>

Output: J
It's easy to get a first letter, the first character is
Echo (substr (C ("script"), 0, 1));
Convert to uppercase:
Echo Strtoupper (substr ("Niu Nu"), 0, 1);
Output: J
Echo (substr (C ("script"), 0,7);
Output: Jiaoben

current 1/2 page   1 2 Next read the full text

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.