Posted in PHP onMarch 21, 2015
本文实例讲述了php中文繁体和简体相互转换的方法。分享给大家供大家参考。具体分析如下:
下面的代码用到了繁体和简体字库对照表,实现繁体与简体字的转换功能
<?php class utf8_chinese { private $utf8_gb2312; private $utf8_big5; private $data; public function __construct($data){ $this->utf8_gb2312 = $data['sim']; $this->utf8_big5 = $data['tra']; } public function gb2312_big5($str) { $str_t = ''; $len = strlen($str); $a = 0; while ($a < $len){ if (ord($str{$a})>=224 && ord($str{$a})<=239){ if (($temp = strpos( $this->utf8_gb2312, $str{$a} . $str{$a+1} . $str{$a+2})) !== false){ $str_t .= $this->utf8_big5{$temp} . $this->utf8_big5{$temp+1} . $this->utf8_big5{$temp+2}; $a += 3; continue; } } $str_t .= $str{$a}; $a += 1; } return $str_t; } public function big5_gb2312($str) { $str_t = ''; $len = strlen($str); $a = 0; while ($a < $len){ if (ord($str{$a})>=224 && ord($str{$a})<=239){ if (($temp = strpos( $this->utf8_big5, $str{$a} . $str{$a+1} . $str{$a+2})) !== false){ $str_t .= $this->utf8_gb2312{$temp} . $this->utf8_gb2312{$temp+1} . $this->utf8_gb2312{$temp+2}; $a += 3; continue; } } $str_t .= $str{$a}; $a += 1; } return $str_t; } } $_UTF8_TRA = array ( 'sim'=>'万与丑专业丛东丝丢两严丧个丬丰临为丽举么义乌乐乔习乡书买乱争于亏云亘亚产亩亲亵??亿仅从仑仓仪们价众优伙会伛伞伟传伤伥伦伧伪伫体余佣佥侠侣侥侦侧侨侩侪侬俣俦俨俩俪俭债倾偬偻偾偿傥傧储傩儿兑兖党兰关兴兹养兽冁内冈册写军农冢冯冲决况冻净凄凉凌减凑凛几凤凫凭凯击凼凿刍划刘则刚创删别?i刭刽刿剀剂剐剑剥剧劝办务劢动励劲劳势勋勐?衷蓉胸亚?交??ヂ袈?蔽晕廊蹿岢???餮寡嶝遣尴嶝上贸?秦讼夭??λ?⒈湫鸬?逗盘具从鹾笙怕缆疬亩痔?粑膺歼脚贿窟略边们何赜竭橇?踢羞暹韵踢呦煅七者剡龠芑┻噙膺嬗催?y唠?|唢唣唤唿啧啬啭啮???ヅ玎多粪亢青刃赅又鲟噜柘?胪旁按盐о鸸?荚彩ホ鄢≯嗷悼榧崽驰薨游敕刈孤③廑淅菘眼疔训孥????垲垴埘埙埚埝埯堑堕?G墙壮声壳壶?状Ρ父垂煌房浼卸徂欺挤芙卑伦备韭桢??f┙?︽??挎?殒存?O婴婵婶媪嫒嫔嫱嬷孙学孪宁宝实宠审宪宫宽宾寝对寻导寿将尔尘尧尴尸尽层?撂虢焓袈佩鹩焖昶襻?卺??暗毫朐泪纯?N峄峡?i峤峥峦崂崃??崭嵘?箩吾嗅蔗酃?媳宜?︵?柿敝拇?“镟???葆ジ刹⒐阕?炻?锌庥γ砼臃?鲡蘅?炱?琶皱蛲涞?抗榈甭?ρ宄咕夺庥?溻阌氢榛程?蒜溻驸赈肓?茼♀?悼叶疋????浙⒃庙ㄐ?ッ蹙?宀页捅广?训?唔?撤咩丛干?\憷懑懒懔戆戋戏戗战戬户扎扑扦执扩扪扫扬扰抚抛抟抠抡抢护报担拟拢拣拥拦拧拨择挂挚挛?ノ翁⑿?拥厕卣跫坊??趟鸺窕坏肪菽砺稗庵赖Р艮柁昀哭觳蟾槁Ы列?戕蟀谝”魈??拍爝⑦_ニ釉艿辛彩??刀氛抖衔蘧墒笨?D昙昼?o显晋晒晓晔晕晖暂暧札术朴机杀杂权条来杨杩杰极构枞枢枣枥枧枨枪枫枭柜柠柽栀栅标栈栉栊栋栌栎栏树栖样栾桊桠桡桢档桤桥桦桧桨桩梦????检棂椁椟椠椤椭楼榄榇榈榉??槛槟槠横樯樱橥橱橹橼檐檩欢欤欧歼殁殇残殒殓殚殡殴毁毂毕毙毡毵氇气氢氩氲汇汉污汤汹沓沟没沣沤沥沦沧?h沩沪?m泞泪泶泷泸泺泻泼泽泾洁洒洼浃浅浆浇浈?缸遣怃?娩?夯脘芭ㄤ?煌坑刻卫凿盗颁段?榛恋尤蠼д巧?碓ㄤ俗珍陆ヤ庞驿缮?掠瓮迨?=︿?句涔鲋弯黉苈?蘼死穆斜跆??礓脘熹蛭?变罄戒?翦懊鸬屏樵植屿韭?漓快恋懔冻闼咐锰?蜓谭成侦腔馓探?然漓遂忪鸯戊职??龟笄N?筷褡瘁钺镉瘫丰螵A狞独狭狮狯狰狱狲猃猎猕猡猪猫猬献獭玑??玛玮环现?玺珉珏珐珑?珲?琏琐琼瑶瑷璇璎瓒瓮瓯电画畅畲畴疖疗疟疠疡疬疮疯疱疴痈痉痒痖痨痪痫痴瘅?瘗瘘瘪瘫瘾瘿癞癣癫癯皑皱皲盏盐监盖盗盘眍眦?着睁睐睑瞒瞩矫矶矾矿砀码砖砗砚砜砺砻砾础?硅硕硖硗??确硷碍碛碜碱碹磙礼?祢祯祷祸禀禄禅离秃秆种积称秽?稆税稣稳穑穷窃窍窑窜窝窥窦窭竖竞笃笋笔笕笺笼笾筑筚筛?筝筹签简?箦箧箨箩箪箫篑篓篮篱簖籁籴类籼粜粝粤粪粮糁糇紧絷纟纠纡红纣纤纥约级纨纩纪纫纬纭?纯纰纱纲纳?纵纶纷纸纹纺??纽纾线绀绁绂练组绅细织终绉绊绋绌绍绎经绐绑绒结绔绕?绗绘给绚绛络绝绞统绠绡绢绣?绥绦继绨绩绪绫?续绮绯绰绱绲绳维绵绶绷绸?绺绻综绽绾绿缀缁缂缃缄缅缆缇缈缉?缋缌缍缎缏?缑缒缓缔缕编缗缘缙缚缛缜缝?缟缠缡缢缣缤缥缦缧缨缩缪缫缬缭缮缯缰缱缲缳缴缵罂网罗罚罢罴羁羟羡翘??耢耧耸耻聂聋职聍联聩聪肃肠肤肷肾肿胀胁胆胜胧胨胪胫胶脉脍脏脐脑脓脔脚脱脶脸腊腌?腭腻腼腽腾膑?舆舣舰舱舻艰艳艹艺节芈芗芜芦苁苇苈苋苌苍苎苏苘苹茎茏茑茔茕茧荆荐?荚荛荜荞荟荠荡荣荤荥荦荧荨荩荪荫荬荭荮药莅莜莱莲莳莴莶获莸莹莺莼?萝萤营萦萧萨葱蒇蒉蒋蒌蓝蓟蓠蓣蓥蓦蔷蔹蔺蔼蕲蕴薮藁藓虏虑虚虫虬虮虽虾虿蚀蚁蚂蚕蚝蚬蛊蛎蛏蛮蛰蛱蛲蛳蛴蜕蜗蜡蝇蝈蝉蝎蝼蝾?螨?衅衔补衬衮袄袅?袜袭?装裆?裢裣裤裥褛褴襁?见观?规觅视觇览觉觊觋觌?觎觏觐觑觞触觯?誉誊讠计订讣认讥讦讧讨让讪讫训议讯记?讲讳讴讵讶讷许讹论?讼讽设访诀证诂诃评诅识?诈诉诊诋诌词诎诏?译诒诓诔试诖诗诘诙诚诛诜话诞诟诠诡询诣诤该详诧诨诩?诫诬语诮误诰诱诲诳说诵诶请诸诹诺读诼诽课诿谀谁谂调谄谅谆谇谈谊谋谌谍谎谏谐谑谒谓谔谕谖谗谘谙谚谛谜谝?谟谠谡谢谣谤谥谦谧谨谩谪谫谬谭谮谯谰谱谲谳谴谵谶谷?贝贞负?贡财责贤败账货质贩贪贫贬购贮贯贰贱贲贳贴贵贶贷贸费贺贻贼贽贾贿赀赁赂赃资赅赆赇赈赉赊赋赌赍赎赏赐??赓赔赕赖?赘赙赚赛赜赝赞?赠赡赢赣?赵赶趋趱趸跃跄跖跞践?跷跸跹跻踊踌踪踬踯蹑蹒蹰蹿躏躜躯车轧轨轩?轫转轭轮软轰轱轲轳轴轵轶轷轸轹轺轻轼载轾轿?辁辂较辄辅辆辇辈辉辊辋?辍辎辏辐辑?输辔辕辖辗辘辙辚辞辩辫边辽达迁过迈运还这进远违连迟迩迳迹适选逊递逦逻遗遥邓邝邬邮邹邺邻郁郄郏郐郑郓郦郧郸酝?酱酽酾酿释里?鉴銮錾钆钇针钉钊钋钌钍钎钏钐?钒钓钔钕?钗?钙钚钛钝钞钟钠钡钢钣钤钥钦钧钨钩钪钫钬钭钮钯钰钱钲钳钴钵钶钷钸钹钺钻钼钽钾钿铀铁铂铃铄铅铆铈铉铊铋铍铎?铐铑铒铕铗铘铙?铛铜铝铞铟铠铡铢铣铤铥?铧铨铪铫铬铭铮铯铰铱铲铳铴铵银铷铸铹铺?铼铽链铿销锁锂锃锄锅锆锇锈锉锊锋锌锍锎锏锐锑锒锓锔锕锖锗错锚?锞锟?锡锢锣锤锥锦锨锩锫锬锭键锯锰锱锲?锴锵锶锷锸锹锺锻锼?锾锿镀镁镂?镆镇?镉镊镌镍镎镏镐镑镒?镖镗镙?镛镜镝镞镟?镡镢镣镤镥镦镧镨镩镪镫镬镭?镯镰镱镲镳?镶长门闩闪闫?闭问闯闰闱闲闳间闵闶闷闸闹闺闻闼闽闾?阀阁阂阃阄阅阆?阈阉阊阋阌阍阎阏阐阑阒?阔阕阖阗?阙阚?队阳阴阵阶际陆陇陈陉陕陧陨险随隐隶隽难雏雠雳雾霁霉霭靓静靥鞑鞒鞯鞴韦韧?韩韪韫韬韵页顶顷顸项顺须顼顽顾顿颀颁颂颃预颅领颇颈颉颊?颌颍?颏颐频?颓颔?颖颗题?颚颛颜额颞颟颠颡颢?颤颥颦颧风??飑飒飓?飕??飘飙飚飞飨餍?饥?饧饨饩饪饫饬饭饮饯饰饱饲?饴饵饶饷??饺?饼饽?饿馀馁??馄馅馆馇馈?馊馋?馍?馏馐馑馒馓馔馕马驭驮驯驰驱?驳驴驵驶驷驸驹驺驻驼驽驾驿骀骁骂?骄骅骆骇骈?骊骋验??骏骐骑骒骓??骖骗骘?骚骛骜骝骞骟骠骡骢骣骤骥?骧髅髋髌鬓魇魉鱼??鱿?鲁鲂?鲅鲆鲇鲈??鲋?鲍鲎?鲐鲑鲒?鲔鲕????鲚鲛鲜?鲞鲟鲠鲡鲢鲣鲤鲥鲦鲧鲨鲩?鲫?鲭鲮?鲰鲱鲲鲳鲴鲵鲶鲷鲸?鲺鲻鲼鲽?????鳃鳄鳅鳆鳇??鳊鳋鳌鳍鳎鳏鳐??鳓鳔鳕鳖鳗鳘鳙?鳜鳝鳞鳟??鳢?鸟鸠鸡鸢鸣?鸥鸦?鸨鸩鸪鸫鸬鸭?鸯?鸱鸲鸳?鸵鸶鸷鸸鸹鸺??鸽鸾鸿?鹁鹂鹃鹄鹅鹆鹇鹈鹉鹊鹋鹌?鹎鹏?鹑???鹕?鹗鹘鹚鹛鹜?鹞????鹣鹤?鹦鹧鹨鹩鹪鹫鹬鹭?鹰鹱?鹳?鹾麦麸黄黉?黩黪黾鼋?鼍鼗鼹齄齐齑齿龀??龃龄龅龆龇龈龉龊龋龌龙龚龛龟志制咨只里系范松没尝尝闹面准钟别闲干尽脏拼', 'tra'=>'?????I??|??G?????爿???辂???????塘????I?y??於????????????|?H???}?x???r???夥???????t?????畜w???L?b?H?e???S?~???z?R????z?????A??E?f??????????键h???????????????V???Q?r??Q?D??R?p???C?坐P??{?P??腓??????t?????h?e?}?q????????????褶k????????烀???Q?T?^???f?钨u?????s???S?d?????????????B?N??P??㈧a??????B???U?\?後?????w??????`??I??h?T?J??柙??U????z吒?j?呱???}?^????W????????O??Z???r?竞?K??数m??c?[???D??肃???u???E?讨o?F?@?????D?A???鲒??K?????]??????????s??|????N??P?_??|???q??????崖????谔??溲}?蝾^??A?Z?Y?J?^??W?y?D????????????I???D??z????????????O?W?\?????????????m?????????????m???票M????????Z?q?????s?S??u?X?[???h?G?F?{?A????n????M??V???饧?p??????????ず?????????缫L??K?V??c?]?T???R??U?F?[?????????????????w???????贫R????n???B?Z???Y????z???????Q??????????a?????K??v??M???T??C???|????怵??????????艏???L??U???P?_????????????M?n???r?Q???????????????D?]???p??Q?v??????S????????v?R????y?z?d?[?u?P???t??f?X?]?x?\?????谍S?挑Y???o??r??????铒@?x??????????????C?㈦s??l???q??O????????g??????n?????f?d??????????????????E?n?????u???????z???????E??????x??????M?{?????春??_?g?e?W???{??????????????л????????????h?@??斑e??]???a?r?S??t?????I??{?o?T?a???????⒏D??\?{??????y???g?I???G????T????Z?i??u??o?????q???Y?O?n?^?u??O?c?B?剡[????R?s?U??L?????M?]?V?E??I???E?u?t???H???z???|?l???綮`??N??t????忘c????q???N?T??????Z?C?a???F?c??糊溜???????????瞰E???????????????????????????????????????????????????迟墚??????????屙????????????????????????????????著????????????????????矽???????????A镟?L?????????????????????????????????????????????????????????????????????????糸??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????u??????????????????V??????????????????????????????????????????????????????L??O???????????s????墒n???????????????????????I?????????????????????槁???]????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????≠~??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????钜???????????????????????????????????J???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????}?忸W???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????谘???S??????L???淑????乾???拚', ); function cns($str){ global $_UTF8_TRA; $chinese = new utf8_chinese($_UTF8_TRA); $str_big5 = $chinese->gb2312_big5($str); return $str_big5; }
希望本文所述对大家的php程序设计有所帮助。
php中文繁体和简体相互转换的方法
- Author -
feige声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@