如题所述
因工作需要编写了一个类,专门做拼音格式的转换,例:李海洋=李海阳,如有同行也有此需求,可直接复制代码,帮新人加点人气,不胜感激。废话不多说,上代码:
?服务器端编程语言(专业超文本预处理器的缩写)
/**
* 步骤:
* 3.根据返回格式分为两步:
* 3.1 未写该参数,提示'请输入返回格式:数组/字符串;
* 3.2 返回格式定义为数组:
* 3.3 返回格式定义为字符串:
*
* 代码主要实现方法deal _全名(全名):
* 名为简写时:J.B。或接线箱或一个字母
* 若无"-"分割,先判断名是否只有一个,有则直接输出,否则进行为循环确定
*/
集体交易_作者
{
静态私有$ this _=null
/**
*/
静态公共函数dealauthor($author_info,$back_mode){
如果(!self:$this_) {
$this_=self:$this_=新的自己;
}否则{
$ this _=self: $ this _
}
$ author _ arr=array();
如果(!is_array($author_info)) {
$author_info=str_replace(',',',',$ author _ info);
$ author _ arr=array _ filter(explode(',',$ author _ info));
}否则{
$ author _ arr=$ author _ info
}
//判断姓的位置
$ is _ surname _ first=$ this _-is _ surname _ first($ author _ arr);
$ after _ process _ author _ array=array();
$ after _ process _ author _ string=" ";
如果(!$back_mode){
'返回'请输入返回格式:数组/字符串;
}elseif($back_mode=='array'){
foreach($ author _ arr as $ single _ author _ name){
$ single _ author _ name=trim($ single _ author _ name);
$ is _ China _ author=$ this _-is _ China _ author($ single _ author _ name,$ is _ surname _ first);
switch ($is_china_author) {
case true:
$ author=$ this _-deal _全名($ is _ China _ author);
$ after _ process _ author _ array[]=$ author;
打破;
案例错误:
$ after _ process _ author _ array[]=$ single _ author _ name;
打破;
}
}
返回$ after _ process _ author _数组
}elseif($back_mode='string'){
foreach($ author _ arr as $ single _ author _ name){
$ single _ author _ name=trim($ single _ author _ name);
$ is _ China _ author=$ this _-is _ China _ author($ single _ author _ name,$ is _ surname _ first);
switch ($is_china_author) {
case true:
$ author=$ this _-deal _全名($ is _ China _ author);
$after_process_author_string .=$author['name']['fullname'].',';
打破;
案例错误:
$after_process_author_string .=$single_author_name .',';
打破;
}
}
返回substr($ after _ process _ author _ string,0,-1);
}
}
/**
*/
private function is_china_author($single_author_name,$is_surname_first){
// 百家姓拼音
$surname = $this->pinyin()[2];
$single_author_name = explode(' ',trim(str_replace(' ',' ',strtolower($single_author_name))));
if(count($single_author_name) != 2){
return false;
}elseif(isset($surname[$single_author_name[0]]) || isset($surname[$single_author_name[1]])){
if($is_surname_first){
$fullname = array(
'firstname'=>strtoupper($single_author_name[0]),
'lastname'=>$single_author_name[1]
);
}else{
$fullname = array(
'firstname'=>strtoupper($single_author_name[1]),
'lastname'=>$single_author_name[0]
);
}
return $fullname;
}else{
return false;
}
}
/**
* $title 拼音封装
*/
private function pinyin(){
$pinyin = array(
'a'=>0,'ai'=>1,'an'=>2,'ang'=>3,'ao'=>4,'ba'=>5,'bai'=>6,'ban'=>7,'bang'=>8,'bao'=>9,'bei'=>10,'ben'=>11,'beng'=>12,'bi'=>13,'bian'=>14,'biao'=>15,'bie'=>16,'bin'=>17,'bing'=>18,'bo'=>19,'bu'=>20,'ca'=>21,'cai'=>22,'can'=>23,'cang'=>24,'cao'=>25,'ce'=>26,'cen'=>26,'ceng'=>27,'cha'=>28,'chai'=>29,'chan'=>30,'chang'=>31,'chao'=>32,'che'=>33,'chen'=>34,'cheng'=>35,'chi'=>36,'chong'=>37,'chou'=>38,'chu'=>39,'chuai'=>40,'chuan'=>41,'chuang'=>42,'chui'=>43,'chun'=>44,'chuo'=>45,'ci'=>46,'cong'=>47,'cou'=>48,'cu'=>49,'cuan'=>50,'cui'=>51,'cun'=>52,'cuo'=>53,'da'=>54,'dai'=>55,'dan'=>56,'dang'=>57,'dao'=>58,'de'=>59,'deng'=>60,'di'=>61,'dian'=>62,'diao'=>63,'die'=>64,'ding'=>65,'diu'=>66,'dong'=>67,'dou'=>68,'du'=>69,'duan'=>70,'dui'=>71,'dun'=>72,'duo'=>73,'e'=>74,'en'=>75,'er'=>76,'fa'=>77,'fan'=>78,'fang'=>79,'fei'=>80,'fen'=>81,'feng'=>82,'fo'=>83,'fou'=>84,'fu'=>85,'ga'=>86,'gai'=>87,'gan'=>88,'gang'=>89,'gao'=>90,'ge'=>91,'gei'=>92,'gen'=>93,'geng'=>94,'gong'=>95,'gou'=>96,'gu'=>97,'gua'=>98,'guai'=>99,'guan'=>100,'guang'=>101,'gui'=>102,'gun'=>103,'guo'=>104,'ha'=>105,'hai'=>106,'han'=>107,'hang'=>108,'hao'=>109,'he'=>110,'hei'=>111,'hen'=>112,'heng'=>113,'hong'=>114,'hou'=>115,'hu'=>116,'hua'=>117,'huai'=>118,'huan'=>119,'huang'=>120,'hui'=>121,'hun'=>122,'huo'=>123,'ji'=>124,'jia'=>125,'jian'=>126,'jiang'=>127,'jiao'=>128,'jie'=>129,'jin'=>130,'jing'=>131,'jiong'=>132,'jiu'=>133,'ju'=>134,'juan'=>135,'jue'=>136,'jun'=>137,'ka'=>138,'kai'=>139,'kan'=>140,'kang'=>141,'kao'=>142,'ke'=>143,'ken'=>144,'keng'=>145,'kong'=>146,'kou'=>147,'ku'=>148,'kua'=>149,'kuai'=>150,'kuan'=>151,'kuang'=>152,'kui'=>153,'kun'=>154,'kuo'=>155,'la'=>156,'lai'=>157,'lan'=>158,'lang'=>159,'lao'=>160,'le'=>161,'lei'=>162,'leng'=>163,'li'=>164,'lia'=>165,'lian'=>166,'liang'=>167,'liao'=>168,'lie'=>169,'lin'=>170,'ling'=>171,'liu'=>172,'long'=>173,'lou'=>174,'lu'=>175,'lv'=>176,'luan'=>177,'lue'=>178,'lun'=>179,'luo'=>180,'ma'=>181,'mai'=>182,'man'=>183,'mang'=>184,'mao'=>185,'me'=>186,'mei'=>187,'men'=>188,'meng'=>189,'mi'=>190,'mian'=>191,'miao'=>192,'mie'=>193,'min'=>194,'ming'=>195,'miu'=>196,'mo'=>197,'mou'=>198,'mu'=>199,'na'=>200,'nai'=>201,'nan'=>202,'nang'=>203,'nao'=>204,'ne'=>205,'nei'=>206,'nen'=>207,'neng'=>208,'ni'=>209,'nian'=>210,'niang'=>211,'niao'=>212,'nie'=>213,'nin'=>214,'ning'=>215,'niu'=>216,'nong'=>217,'nu'=>218,'nv'=>219,'nuan'=>220,'nue'=>221,'nuo'=>222,'o'=>223,'ou'=>224,'pa'=>225,'pai'=>226,'pan'=>227,'pang'=>228,'pao'=>229,'pei'=>230,'pen'=>231,'peng'=>232,'pi'=>233,'pian'=>234,'piao'=>235,'pie'=>236,'pin'=>237,'ping'=>238,'po'=>239,'pu'=>240,'qi'=>241,'qia'=>242,'qian'=>243,'qiang'=>244,'qiao'=>245,'qie'=>246,'qin'=>247,'qing'=>248,'qiong'=>249,'qiu'=>250,'qu'=>251,'quan'=>252,'que'=>253,'qun'=>254,'ran'=>255,'rang'=>256,'rao'=>257,'re'=>258,'ren'=>259,'reng'=>260,'ri'=>261,'rong'=>262,'rou'=>263,'ru'=>264,'ruan'=>265,'rui'=>266,'run'=>267,'ruo'=>268,'sa'=>269,'sai'=>270,'san'=>271,'sang'=>272,'sao'=>273,'se'=>274,'sen'=>275,'seng'=>276,'sha'=>277,'shai'=>278,'shan'=>279,'shang'=>280,'shao'=>281,'she'=>282,'shen'=>283,'sheng'=>284,'shi'=>285,'shou'=>286,'shu'=>287,'shua'=>288,'shuai'=>289,'shuan'=>290,'shuang'=>291,'shui'=>292,'shun'=>293,'shuo'=>294,'si'=>295,'song'=>296,'sou'=>297,'su'=>298,'suan'=>299,'sui'=>300,'sun'=>301,'suo'=>302,'ta'=>303,'tai'=>304,'tan'=>305,'tang'=>306,'tao'=>307,'te'=>308,'teng'=>309,'ti'=>310,'tian'=>311,'tiao'=>312,'tie'=>313,'ting'=>314,'tong'=>315,'tou'=>316,'tu'=>317,'tuan'=>318,'tui'=>319,'tun'=>320,'tuo'=>321,'wa'=>322,'wai'=>323,'wan'=>324,'wang'=>325,'wei'=>326,'wen'=>327,'weng'=>328,'wo'=>329,'wu'=>330,'xi'=>331,'xia'=>332,'xian'=>333,'xiang'=>334,'xiao'=>335,'xie'=>336,'xin'=>337,'xing'=>338,'xiong'=>339,'xiu'=>340,'xu'=>341,'xuan'=>342,'xue'=>343,'xun'=>344,'ya'=>345,'yan'=>346,'yang'=>347,'yao'=>348,'ye'=>349,'yi'=>350,'yin'=>351,'ying'=>352,'yo'=>353,'yong'=>354,'you'=>355,'yu'=>356,'yuan'=>357,'yue'=>358,'yun'=>359,'za'=>360,'zai'=>361,'zan'=>362,'zang'=>363,'zao'=>364,'ze'=>365,'zei'=>366,'zen'=>367,'zeng'=>368,'zha'=>369,'zhai'=>370,'zhan'=>371,'zhang'=>372,'zhao'=>373,'zhe'=>374,'zhen'=>375,'zheng'=>376,'zhi'=>377,'zhong'=>378,'zhou'=>379,'zhu'=>380,'zhua'=>381,'zhuai'=>382,'zhuan'=>383,'zhuang'=>384,'zhui'=>385,'zhun'=>386,'zhuo'=>387,'zi'=>388,'zong'=>389,'zou'=>390,'zu'=>391,'zuan'=>392,'zui'=>393,'zun'=>394,'zuo'=>395
);
$surname = array('ai'=>0,'aixinjueluo'=>1,'an'=>2,'ao'=>3,'ba'=>4,'bai'=>5,'baili'=>6,'ban'=>7,'bao'=>8,'bei'=>9,'ben'=>10,'bi'=>11,'bilu'=>12,'bian'=>13,'bie'=>14,'bing'=>15,'bo'=>16,'boerjijin'=>17,'boshang'=>18,'bu'=>19,'cai'=>20,'cang'=>21,'cao'=>22,'cen'=>23,'chai'=>24,'chanyu'=>25,'chang'=>26,'chao'=>27,'che'=>28,'chen'=>29,'cheng'=>30,'ci'=>301,'chi'=>31,'chong'=>32,'chou'=>321,'chu'=>33,'chuan'=>331,'chunyu'=>34,'cong'=>35,'cui'=>36,'dai'=>37,'dang'=>38,'dao'=>39,'deng'=>40,'di'=>41,'diwu'=>42,'diao'=>43,'ding'=>44,'dong'=>45,'dongfang'=>46,'dongguo'=>47,'dongmen'=>48,'dou'=>49,'du'=>50,'dugu'=>51,'duanmu'=>52,'duan'=>53,'duangan'=>54,'duo'=>55,'eerdeyu'=>56,'e'=>57,'fa'=>58,'fan'=>59,'fang'=>60,'fei'=>61,'feng'=>62,'fu'=>63,'fucha'=>64,'gai'=>65,'gan'=>66,'gang'=>67,'gao'=>68,'ge'=>69,'geng'=>70,'gong'=>71,'gongliang'=>72,'gongsun'=>73,'gongxi'=>74,'gongyang'=>75,'gongye'=>76,'gou'=>77,'goukang'=>78,'gu'=>79,'guliang'=>80,'guan'=>81,'guang'=>82,'gui'=>83,'guihai'=>84,'guo'=>85,'hai'=>86,'han'=>87,'hang'=>88,'hao'=>89,'he'=>90,'helian'=>91,'hesheli'=>92,'heng'=>93,'hong'=>94,'hou'=>95,'huyan'=>96,'hu'=>97,'hua'=>98,'huai'=>99,'huan'=>100,'huang'=>101,'huangfu'=>102,'hui'=>103,'hun'=>104,'huo'=>105,'ji'=>106,'jia'=>107,'jiagu'=>108,'jian'=>109,'jiang'=>110,'jiao'=>111,'jie'=>112,'jin'=>113,'jinchu'=>114,'jing'=>115,'jiu'=>116,'ju'=>117,'jun'=>1171,'juan'=>1172,'jueercha'=>118,'ka'=>119,'kan'=>120,'kang'=>121,'ke'=>122,'kong'=>123,'kou'=>124,'kuyala'=>125,'kuai'=>126,'kuang'=>127,'kuanghou'=>128,'kui'=>129,'lai'=>130,'lan'=>131,'lang'=>132,'lao'=>133,'lei'=>134,'le'=>1351,'leng'=>135,'li'=>136,'lian'=>137,'liang'=>138,'liangqiu'=>139,'liao'=>140,'lin'=>141,'ling'=>142,'linghu'=>143,'liu'=>144,'long'=>145,'lou'=>146,'lyu'=>1471,'lu'=>147,'luan'=>148,'luo'=>149,'lvqiu'=>150,'lv'=>151,'ma'=>152,'mai'=>153,'man'=>154,'mao'=>155,'mei'=>156,'men'=>157,'meng'=>158,'mi'=>159,'miao'=>160,'min'=>161,'ming'=>162,'miu'=>163,'mo'=>164,'moha'=>165,'moqi'=>166,'mu'=>167,'murong'=>168,'na'=>169,'nala'=>170,'nan'=>171,'nangong'=>172,'nanmen'=>173,'neyinfucha'=>174,'neng'=>175,'ni'=>176,'nianai'=>177,'nie'=>178,'ning'=>179,'niu'=>180,'niuhulu'=>181,'nong'=>182,'ou'=>183,'ouyang'=>184,'pan'=>185,'pang'=>186,'pei'=>187,'peng'=>188,'pi'=>189,'piao'=>190,'ping'=>191,'pu'=>192,'puyang'=>193,'qi'=>194,'qidiao'=>195,'qiguan'=>196,'qian'=>197,'qiang'=>198,'qiao'=>199,'qiaoda'=>200,'qin'=>201,'qing'=>202,'qiong'=>203,'qiu'=>204,'qu'=>205,'quan'=>206,'que'=>207,'ran'=>208,'rangsi'=>209,'rang'=>210,'rao'=>211,'ren'=>212,'rong'=>213,'ru'=>214,'ruyan'=>215,'ruan'=>216,'rui'=>217,'sahala'=>218,'sakeda'=>219,'samala'=>220,'sa'=>221,'sai'=>222,'sang'=>223,'sha'=>224,'shan'=>225,'shang'=>226,'shangmou'=>227,'shangguan'=>228,'shao'=>229,'she'=>230,'sheer'=>231,'sh