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 ;
}

Posted on 2010-03-11 16:57  古代  阅读(220)  评论(0编辑  收藏  举报