global $pinyindata; $pinyindata = file_get_contents( dirname(__FILE__).'/WINPY.TXT') ; function pinyin($str , $type='all') { global $pinyindata; $ret = '' ; $data = $pinyindata; for($i=0;$i<strlen($str);$i++){ if(ord($str[$i])>0x80){ $c = $str[$i].$str[++$i]; $frompos = strpos($data , $c) ; if($frompos){ $topos = strpos($data,"\n",$frompos+strlen($c)); $start = $frompos+strlen($c); $end = $topos-$start; $txt = substr($data,$start,$end); if($type=='all'){ $ret .= $txt ; }else if($type=='first'){ $ret .=substr($txt , 0 , 1) ; } } }else{ $ret .=$str[$i] ; } } return $ret ; }
|
请发表评论