Home > Backend Development > PHP Tutorial > PHP UTF-8 Chinese to Pinyin processing class

PHP UTF-8 Chinese to Pinyin processing class

WBOY
Release: 2016-07-28 08:29:30
Original
1133 people have browsed it

Reprinted from: http://blog.csdn.net/hzbigdog/article/details/37817135

<code><span><?php</span><span>/**
 * PHP 汉字转拼音
 *<span> @author</span> Jerryli(hzjerry@gmail.com)
 *<span> @version</span> V0.20140715
 *<span> @package</span> SPFW.core.lib.final
 *<span> @global</span> SEA_PHP_FW_VAR_ENV
 *<span> @example</span>
 *  echo CUtf8_PY::encode('阿里巴巴科技有限公司'); //编码为拼音首字母
 *  echo CUtf8_PY::encode('阿里巴巴科技有限公司', 'all'); //编码为全拼音
 */</span><span><span>class</span><span>CUtf8_PY</span> {</span><span>/**
     * 拼音字符转换图
     *<span> @var</span> array
     */</span><span>private</span><span>static</span><span>$_aMaps</span> = <span>array</span>(
        <span>'a'</span>=>-<span>20319</span>,<span>'ai'</span>=>-<span>20317</span>,<span>'an'</span>=>-<span>20304</span>,<span>'ang'</span>=>-<span>20295</span>,<span>'ao'</span>=>-<span>20292</span>,
        <span>'ba'</span>=>-<span>20283</span>,<span>'bai'</span>=>-<span>20265</span>,<span>'ban'</span>=>-<span>20257</span>,<span>'bang'</span>=>-<span>20242</span>,<span>'bao'</span>=>-<span>20230</span>,<span>'bei'</span>=>-<span>20051</span>,<span>'ben'</span>=>-<span>20036</span>,<span>'beng'</span>=>-<span>20032</span>,<span>'bi'</span>=>-<span>20026</span>,<span>'bian'</span>=>-<span>20002</span>,<span>'biao'</span>=>-<span>19990</span>,<span>'bie'</span>=>-<span>19986</span>,<span>'bin'</span>=>-<span>19982</span>,<span>'bing'</span>=>-<span>19976</span>,<span>'bo'</span>=>-<span>19805</span>,<span>'bu'</span>=>-<span>19784</span>,
        <span>'ca'</span>=>-<span>19775</span>,<span>'cai'</span>=>-<span>19774</span>,<span>'can'</span>=>-<span>19763</span>,<span>'cang'</span>=>-<span>19756</span>,<span>'cao'</span>=>-<span>19751</span>,<span>'ce'</span>=>-<span>19746</span>,<span>'ceng'</span>=>-<span>19741</span>,<span>'cha'</span>=>-<span>19739</span>,<span>'chai'</span>=>-<span>19728</span>,<span>'chan'</span>=>-<span>19725</span>,<span>'chang'</span>=>-<span>19715</span>,<span>'chao'</span>=>-<span>19540</span>,<span>'che'</span>=>-<span>19531</span>,<span>'chen'</span>=>-<span>19525</span>,<span>'cheng'</span>=>-<span>19515</span>,<span>'chi'</span>=>-<span>19500</span>,<span>'chong'</span>=>-<span>19484</span>,<span>'chou'</span>=>-<span>19479</span>,<span>'chu'</span>=>-<span>19467</span>,<span>'chuai'</span>=>-<span>19289</span>,<span>'chuan'</span>=>-<span>19288</span>,<span>'chuang'</span>=>-<span>19281</span>,<span>'chui'</span>=>-<span>19275</span>,<span>'chun'</span>=>-<span>19270</span>,<span>'chuo'</span>=>-<span>19263</span>,<span>'ci'</span>=>-<span>19261</span>,<span>'cong'</span>=>-<span>19249</span>,<span>'cou'</span>=>-<span>19243</span>,<span>'cu'</span>=>-<span>19242</span>,<span>'cuan'</span>=>-<span>19238</span>,<span>'cui'</span>=>-<span>19235</span>,<span>'cun'</span>=>-<span>19227</span>,<span>'cuo'</span>=>-<span>19224</span>,
        <span>'da'</span>=>-<span>19218</span>,<span>'dai'</span>=>-<span>19212</span>,<span>'dan'</span>=>-<span>19038</span>,<span>'dang'</span>=>-<span>19023</span>,<span>'dao'</span>=>-<span>19018</span>,<span>'de'</span>=>-<span>19006</span>,<span>'deng'</span>=>-<span>19003</span>,<span>'di'</span>=>-<span>18996</span>,<span>'dian'</span>=>-<span>18977</span>,<span>'diao'</span>=>-<span>18961</span>,<span>'die'</span>=>-<span>18952</span>,<span>'ding'</span>=>-<span>18783</span>,<span>'diu'</span>=>-<span>18774</span>,<span>'dong'</span>=>-<span>18773</span>,<span>'dou'</span>=>-<span>18763</span>,<span>'du'</span>=>-<span>18756</span>,<span>'duan'</span>=>-<span>18741</span>,<span>'dui'</span>=>-<span>18735</span>,<span>'dun'</span>=>-<span>18731</span>,<span>'duo'</span>=>-<span>18722</span>,
        <span>'e'</span>=>-<span>18710</span>,<span>'en'</span>=>-<span>18697</span>,<span>'er'</span>=>-<span>18696</span>,
        <span>'fa'</span>=>-<span>18526</span>,<span>'fan'</span>=>-<span>18518</span>,<span>'fang'</span>=>-<span>18501</span>,<span>'fei'</span>=>-<span>18490</span>,<span>'fen'</span>=>-<span>18478</span>,<span>'feng'</span>=>-<span>18463</span>,<span>'fo'</span>=>-<span>18448</span>,<span>'fou'</span>=>-<span>18447</span>,<span>'fu'</span>=>-<span>18446</span>,
        <span>'ga'</span>=>-<span>18239</span>,<span>'gai'</span>=>-<span>18237</span>,<span>'gan'</span>=>-<span>18231</span>,<span>'gang'</span>=>-<span>18220</span>,<span>'gao'</span>=>-<span>18211</span>,<span>'ge'</span>=>-<span>18201</span>,<span>'gei'</span>=>-<span>18184</span>,<span>'gen'</span>=>-<span>18183</span>,<span>'geng'</span>=>-<span>18181</span>,<span>'gong'</span>=>-<span>18012</span>,<span>'gou'</span>=>-<span>17997</span>,<span>'gu'</span>=>-<span>17988</span>,<span>'gua'</span>=>-<span>17970</span>,<span>'guai'</span>=>-<span>17964</span>,<span>'guan'</span>=>-<span>17961</span>,<span>'guang'</span>=>-<span>17950</span>,<span>'gui'</span>=>-<span>17947</span>,<span>'gun'</span>=>-<span>17931</span>,<span>'guo'</span>=>-<span>17928</span>,
        <span>'ha'</span>=>-<span>17922</span>,<span>'hai'</span>=>-<span>17759</span>,<span>'han'</span>=>-<span>17752</span>,<span>'hang'</span>=>-<span>17733</span>,<span>'hao'</span>=>-<span>17730</span>,<span>'he'</span>=>-<span>17721</span>,<span>'hei'</span>=>-<span>17703</span>,<span>'hen'</span>=>-<span>17701</span>,<span>'heng'</span>=>-<span>17697</span>,<span>'hong'</span>=>-<span>17692</span>,<span>'hou'</span>=>-<span>17683</span>,<span>'hu'</span>=>-<span>17676</span>,<span>'hua'</span>=>-<span>17496</span>,<span>'huai'</span>=>-<span>17487</span>,<span>'huan'</span>=>-<span>17482</span>,<span>'huang'</span>=>-<span>17468</span>,<span>'hui'</span>=>-<span>17454</span>,<span>'hun'</span>=>-<span>17433</span>,<span>'huo'</span>=>-<span>17427</span>,
        <span>'ji'</span>=>-<span>17417</span>,<span>'jia'</span>=>-<span>17202</span>,<span>'jian'</span>=>-<span>17185</span>,<span>'jiang'</span>=>-<span>16983</span>,<span>'jiao'</span>=>-<span>16970</span>,<span>'jie'</span>=>-<span>16942</span>,<span>'jin'</span>=>-<span>16915</span>,<span>'jing'</span>=>-<span>16733</span>,<span>'jiong'</span>=>-<span>16708</span>,<span>'jiu'</span>=>-<span>16706</span>,<span>'ju'</span>=>-<span>16689</span>,<span>'juan'</span>=>-<span>16664</span>,<span>'jue'</span>=>-<span>16657</span>,<span>'jun'</span>=>-<span>16647</span>,
        <span>'ka'</span>=>-<span>16474</span>,<span>'kai'</span>=>-<span>16470</span>,<span>'kan'</span>=>-<span>16465</span>,<span>'kang'</span>=>-<span>16459</span>,<span>'kao'</span>=>-<span>16452</span>,<span>'ke'</span>=>-<span>16448</span>,<span>'ken'</span>=>-<span>16433</span>,<span>'keng'</span>=>-<span>16429</span>,<span>'kong'</span>=>-<span>16427</span>,<span>'kou'</span>=>-<span>16423</span>,<span>'ku'</span>=>-<span>16419</span>,<span>'kua'</span>=>-<span>16412</span>,<span>'kuai'</span>=>-<span>16407</span>,<span>'kuan'</span>=>-<span>16403</span>,<span>'kuang'</span>=>-<span>16401</span>,<span>'kui'</span>=>-<span>16393</span>,<span>'kun'</span>=>-<span>16220</span>,<span>'kuo'</span>=>-<span>16216</span>,
        <span>'la'</span>=>-<span>16212</span>,<span>'lai'</span>=>-<span>16205</span>,<span>'lan'</span>=>-<span>16202</span>,<span>'lang'</span>=>-<span>16187</span>,<span>'lao'</span>=>-<span>16180</span>,<span>'le'</span>=>-<span>16171</span>,<span>'lei'</span>=>-<span>16169</span>,<span>'leng'</span>=>-<span>16158</span>,<span>'li'</span>=>-<span>16155</span>,<span>'lia'</span>=>-<span>15959</span>,<span>'lian'</span>=>-<span>15958</span>,<span>'liang'</span>=>-<span>15944</span>,<span>'liao'</span>=>-<span>15933</span>,<span>'lie'</span>=>-<span>15920</span>,<span>'lin'</span>=>-<span>15915</span>,<span>'ling'</span>=>-<span>15903</span>,<span>'liu'</span>=>-<span>15889</span>,<span>'long'</span>=>-<span>15878</span>,<span>'lou'</span>=>-<span>15707</span>,<span>'lu'</span>=>-<span>15701</span>,<span>'lv'</span>=>-<span>15681</span>,<span>'luan'</span>=>-<span>15667</span>,<span>'lue'</span>=>-<span>15661</span>,<span>'lun'</span>=>-<span>15659</span>,<span>'luo'</span>=>-<span>15652</span>,
        <span>'ma'</span>=>-<span>15640</span>,<span>'mai'</span>=>-<span>15631</span>,<span>'man'</span>=>-<span>15625</span>,<span>'mang'</span>=>-<span>15454</span>,<span>'mao'</span>=>-<span>15448</span>,<span>'me'</span>=>-<span>15436</span>,<span>'mei'</span>=>-<span>15435</span>,<span>'men'</span>=>-<span>15419</span>,<span>'meng'</span>=>-<span>15416</span>,<span>'mi'</span>=>-<span>15408</span>,<span>'mian'</span>=>-<span>15394</span>,<span>'miao'</span>=>-<span>15385</span>,<span>'mie'</span>=>-<span>15377</span>,<span>'min'</span>=>-<span>15375</span>,<span>'ming'</span>=>-<span>15369</span>,<span>'miu'</span>=>-<span>15363</span>,<span>'mo'</span>=>-<span>15362</span>,<span>'mou'</span>=>-<span>15183</span>,<span>'mu'</span>=>-<span>15180</span>,
        <span>'na'</span>=>-<span>15165</span>,<span>'nai'</span>=>-<span>15158</span>,<span>'nan'</span>=>-<span>15153</span>,<span>'nang'</span>=>-<span>15150</span>,<span>'nao'</span>=>-<span>15149</span>,<span>'ne'</span>=>-<span>15144</span>,<span>'nei'</span>=>-<span>15143</span>,<span>'nen'</span>=>-<span>15141</span>,<span>'neng'</span>=>-<span>15140</span>,<span>'ni'</span>=>-<span>15139</span>,<span>'nian'</span>=>-<span>15128</span>,<span>'niang'</span>=>-<span>15121</span>,<span>'niao'</span>=>-<span>15119</span>,<span>'nie'</span>=>-<span>15117</span>,<span>'nin'</span>=>-<span>15110</span>,<span>'ning'</span>=>-<span>15109</span>,<span>'niu'</span>=>-<span>14941</span>,<span>'nong'</span>=>-<span>14937</span>,<span>'nu'</span>=>-<span>14933</span>,<span>'nv'</span>=>-<span>14930</span>,<span>'nuan'</span>=>-<span>14929</span>,<span>'nue'</span>=>-<span>14928</span>,<span>'nuo'</span>=>-<span>14926</span>,
        <span>'o'</span>=>-<span>14922</span>,<span>'ou'</span>=>-<span>14921</span>,
        <span>'pa'</span>=>-<span>14914</span>,<span>'pai'</span>=>-<span>14908</span>,<span>'pan'</span>=>-<span>14902</span>,<span>'pang'</span>=>-<span>14894</span>,<span>'pao'</span>=>-<span>14889</span>,<span>'pei'</span>=>-<span>14882</span>,<span>'pen'</span>=>-<span>14873</span>,<span>'peng'</span>=>-<span>14871</span>,<span>'pi'</span>=>-<span>14857</span>,<span>'pian'</span>=>-<span>14678</span>,<span>'piao'</span>=>-<span>14674</span>,<span>'pie'</span>=>-<span>14670</span>,<span>'pin'</span>=>-<span>14668</span>,<span>'ping'</span>=>-<span>14663</span>,<span>'po'</span>=>-<span>14654</span>,<span>'pu'</span>=>-<span>14645</span>,
        <span>'qi'</span>=>-<span>14630</span>,<span>'qia'</span>=>-<span>14594</span>,<span>'qian'</span>=>-<span>14429</span>,<span>'qiang'</span>=>-<span>14407</span>,<span>'qiao'</span>=>-<span>14399</span>,<span>'qie'</span>=>-<span>14384</span>,<span>'qin'</span>=>-<span>14379</span>,<span>'qing'</span>=>-<span>14368</span>,<span>'qiong'</span>=>-<span>14355</span>,<span>'qiu'</span>=>-<span>14353</span>,<span>'qu'</span>=>-<span>14345</span>,<span>'quan'</span>=>-<span>14170</span>,<span>'que'</span>=>-<span>14159</span>,<span>'qun'</span>=>-<span>14151</span>,
        <span>'ran'</span>=>-<span>14149</span>,<span>'rang'</span>=>-<span>14145</span>,<span>'rao'</span>=>-<span>14140</span>,<span>'re'</span>=>-<span>14137</span>,<span>'ren'</span>=>-<span>14135</span>,<span>'reng'</span>=>-<span>14125</span>,<span>'ri'</span>=>-<span>14123</span>,<span>'rong'</span>=>-<span>14122</span>,<span>'rou'</span>=>-<span>14112</span>,<span>'ru'</span>=>-<span>14109</span>,<span>'ruan'</span>=>-<span>14099</span>,<span>'rui'</span>=>-<span>14097</span>,<span>'run'</span>=>-<span>14094</span>,<span>'ruo'</span>=>-<span>14092</span>,
        <span>'sa'</span>=>-<span>14090</span>,<span>'sai'</span>=>-<span>14087</span>,<span>'san'</span>=>-<span>14083</span>,<span>'sang'</span>=>-<span>13917</span>,<span>'sao'</span>=>-<span>13914</span>,<span>'se'</span>=>-<span>13910</span>,<span>'sen'</span>=>-<span>13907</span>,<span>'seng'</span>=>-<span>13906</span>,<span>'sha'</span>=>-<span>13905</span>,<span>'shai'</span>=>-<span>13896</span>,<span>'shan'</span>=>-<span>13894</span>,<span>'shang'</span>=>-<span>13878</span>,<span>'shao'</span>=>-<span>13870</span>,<span>'she'</span>=>-<span>13859</span>,<span>'shen'</span>=>-<span>13847</span>,<span>'sheng'</span>=>-<span>13831</span>,<span>'shi'</span>=>-<span>13658</span>,<span>'shou'</span>=>-<span>13611</span>,<span>'shu'</span>=>-<span>13601</span>,<span>'shua'</span>=>-<span>13406</span>,<span>'shuai'</span>=>-<span>13404</span>,<span>'shuan'</span>=>-<span>13400</span>,<span>'shuang'</span>=>-<span>13398</span>,<span>'shui'</span>=>-<span>13395</span>,<span>'shun'</span>=>-<span>13391</span>,<span>'shuo'</span>=>-<span>13387</span>,<span>'si'</span>=>-<span>13383</span>,<span>'song'</span>=>-<span>13367</span>,<span>'sou'</span>=>-<span>13359</span>,<span>'su'</span>=>-<span>13356</span>,<span>'suan'</span>=>-<span>13343</span>,<span>'sui'</span>=>-<span>13340</span>,<span>'sun'</span>=>-<span>13329</span>,<span>'suo'</span>=>-<span>13326</span>,
        <span>'ta'</span>=>-<span>13318</span>,<span>'tai'</span>=>-<span>13147</span>,<span>'tan'</span>=>-<span>13138</span>,<span>'tang'</span>=>-<span>13120</span>,<span>'tao'</span>=>-<span>13107</span>,<span>'te'</span>=>-<span>13096</span>,<span>'teng'</span>=>-<span>13095</span>,<span>'ti'</span>=>-<span>13091</span>,<span>'tian'</span>=>-<span>13076</span>,<span>'tiao'</span>=>-<span>13068</span>,<span>'tie'</span>=>-<span>13063</span>,<span>'ting'</span>=>-<span>13060</span>,<span>'tong'</span>=>-<span>12888</span>,<span>'tou'</span>=>-<span>12875</span>,<span>'tu'</span>=>-<span>12871</span>,<span>'tuan'</span>=>-<span>12860</span>,<span>'tui'</span>=>-<span>12858</span>,<span>'tun'</span>=>-<span>12852</span>,<span>'tuo'</span>=>-<span>12849</span>,
        <span>'wa'</span>=>-<span>12838</span>,<span>'wai'</span>=>-<span>12831</span>,<span>'wan'</span>=>-<span>12829</span>,<span>'wang'</span>=>-<span>12812</span>,<span>'wei'</span>=>-<span>12802</span>,<span>'wen'</span>=>-<span>12607</span>,<span>'weng'</span>=>-<span>12597</span>,<span>'wo'</span>=>-<span>12594</span>,<span>'wu'</span>=>-<span>12585</span>,
        <span>'xi'</span>=>-<span>12556</span>,<span>'xia'</span>=>-<span>12359</span>,<span>'xian'</span>=>-<span>12346</span>,<span>'xiang'</span>=>-<span>12320</span>,<span>'xiao'</span>=>-<span>12300</span>,<span>'xie'</span>=>-<span>12120</span>,<span>'xin'</span>=>-<span>12099</span>,<span>'xing'</span>=>-<span>12089</span>,<span>'xiong'</span>=>-<span>12074</span>,<span>'xiu'</span>=>-<span>12067</span>,<span>'xu'</span>=>-<span>12058</span>,<span>'xuan'</span>=>-<span>12039</span>,<span>'xue'</span>=>-<span>11867</span>,<span>'xun'</span>=>-<span>11861</span>,
        <span>'ya'</span>=>-<span>11847</span>,<span>'yan'</span>=>-<span>11831</span>,<span>'yang'</span>=>-<span>11798</span>,<span>'yao'</span>=>-<span>11781</span>,<span>'ye'</span>=>-<span>11604</span>,<span>'yi'</span>=>-<span>11589</span>,<span>'yin'</span>=>-<span>11536</span>,<span>'ying'</span>=>-<span>11358</span>,<span>'yo'</span>=>-<span>11340</span>,<span>'yong'</span>=>-<span>11339</span>,<span>'you'</span>=>-<span>11324</span>,<span>'yu'</span>=>-<span>11303</span>,<span>'yuan'</span>=>-<span>11097</span>,<span>'yue'</span>=>-<span>11077</span>,<span>'yun'</span>=>-<span>11067</span>,
        <span>'za'</span>=>-<span>11055</span>,<span>'zai'</span>=>-<span>11052</span>,<span>'zan'</span>=>-<span>11045</span>,<span>'zang'</span>=>-<span>11041</span>,<span>'zao'</span>=>-<span>11038</span>,<span>'ze'</span>=>-<span>11024</span>,<span>'zei'</span>=>-<span>11020</span>,<span>'zen'</span>=>-<span>11019</span>,<span>'zeng'</span>=>-<span>11018</span>,<span>'zha'</span>=>-<span>11014</span>,<span>'zhai'</span>=>-<span>10838</span>,<span>'zhan'</span>=>-<span>10832</span>,<span>'zhang'</span>=>-<span>10815</span>,<span>'zhao'</span>=>-<span>10800</span>,<span>'zhe'</span>=>-<span>10790</span>,<span>'zhen'</span>=>-<span>10780</span>,<span>'zheng'</span>=>-<span>10764</span>,<span>'zhi'</span>=>-<span>10587</span>,<span>'zhong'</span>=>-<span>10544</span>,<span>'zhou'</span>=>-<span>10533</span>,<span>'zhu'</span>=>-<span>10519</span>,<span>'zhua'</span>=>-<span>10331</span>,<span>'zhuai'</span>=>-<span>10329</span>,<span>'zhuan'</span>=>-<span>10328</span>,<span>'zhuang'</span>=>-<span>10322</span>,<span>'zhui'</span>=>-<span>10315</span>,<span>'zhun'</span>=>-<span>10309</span>,<span>'zhuo'</span>=>-<span>10307</span>,<span>'zi'</span>=>-<span>10296</span>,<span>'zong'</span>=>-<span>10281</span>,<span>'zou'</span>=>-<span>10274</span>,<span>'zu'</span>=>-<span>10270</span>,<span>'zuan'</span>=>-<span>10262</span>,<span>'zui'</span>=>-<span>10260</span>,<span>'zun'</span>=>-<span>10256</span>,<span>'zuo'</span>=>-<span>10254</span>
    );

    <span>/**
     * 将中文编码成拼音
     *<span> @param</span> string $utf8Data utf8字符集数据
     *<span> @param</span> string $sRetFormat 返回格式 [head:首字母|all:全拼音]
     *<span> @return</span> string
     */</span><span>public</span><span>static</span><span><span>function</span><span>encode</span><span>(<span>$utf8Data</span>, <span>$sRetFormat</span>=<span>'head'</span>)</span>{</span><span>$sGBK</span> = iconv(<span>'UTF-8'</span>, <span>'GBK'</span>, <span>$utf8Data</span>);
        <span>$aBuf</span> = <span>array</span>();
        <span>for</span> (<span>$i</span>=<span>0</span>, <span>$iLoop</span>=strlen(<span>$sGBK</span>); <span>$i</span><<span>$iLoop</span>; <span>$i</span>++) {
            <span>$iChr</span> = ord(<span>$sGBK</span>{<span>$i</span>});
            <span>if</span> (<span>$iChr</span>><span>160</span>)
                <span>$iChr</span> = (<span>$iChr</span><<<span>8</span>) + ord(<span>$sGBK</span>{++<span>$i</span>}) - <span>65536</span>;
            <span>if</span> (<span>'head'</span> === <span>$sRetFormat</span>)
                <span>$aBuf</span>[] = substr(<span>self</span>::zh2py(<span>$iChr</span>),<span>0</span>,<span>1</span>);
            <span>else</span><span>$aBuf</span>[] = <span>self</span>::zh2py(<span>$iChr</span>);
        }
        <span>if</span> (<span>'head'</span> === <span>$sRetFormat</span>)
            <span>return</span> implode(<span>''</span>, <span>$aBuf</span>);
        <span>else</span><span>return</span> implode(<span>' '</span>, <span>$aBuf</span>);
    }

    <span>/**
     * 中文转换到拼音(每次处理一个字符)
     *<span> @param</span> number $iWORD 待处理字符双字节
     *<span> @return</span> string 拼音
     */</span><span>private</span><span>static</span><span><span>function</span><span>zh2py</span><span>(<span>$iWORD</span>)</span> {</span><span>if</span>(<span>$iWORD</span>><span>0</span> && <span>$iWORD</span><<span>160</span> ) {
            <span>return</span> chr(<span>$iWORD</span>);
        } <span>elseif</span> (<span>$iWORD</span><-<span>20319</span>||<span>$iWORD</span>>-<span>10247</span>) {
            <span>return</span><span>''</span>;
        } <span>else</span> {
            <span>foreach</span> (<span>self</span>::<span>$_aMaps</span><span>as</span><span>$py</span> => <span>$code</span>) {
                <span>if</span>(<span>$code</span> > <span>$iWORD</span>) <span>break</span>;
                <span>$result</span> = <span>$py</span>;
            }
            <span>return</span><span>$result</span>;
        }
    }
}
<span>?></span></span></code>
Copy after login

Optimizes the traditional Pinyin conversion processing algorithm, specifically processing the UTF-8 character set.
If you use the GBK or GB2312 character set, you only need to remove the iconv function and assign the value directly without conversion.

Not much to say, just upload the code, it is completely open source and you can use it directly. If you find it useful, please help retain the author's information when using it.

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above has introduced PHP's UTF-8 Chinese to Pinyin processing class, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template