拼音转换汉字翻译器_把汉字转换成拼音代码

更新时间:2016-07-05    来源:php常用代码    手机版     字体:

【www.bbyears.com--php常用代码】

$piny = array(
    "a"=>-20319,
    "ai"=>-20317,
    "an"=>-20304,
    "ang"=>-20295
    );
echo  getChineseSpells("中国WEB第一站 www.111cn.net");
//取汉字所有拼音
function getChineseSpells($chinese, $delimiter = " ", $first=0)
 {
  $result = array();
  for ($i=0; $i    $p = ord(substr($chinese,$i,1));
   if ($p>160) {
    $q = ord(substr($chinese,++$i,1));
    $p = $p*256 + $q - 65536;
   }
   $result[] = getChineseSpell($p);
   if ($first) {
    return $result[0];
   }
  }
  return implode($delimiter, $result);
 }
 
//取一个汉字码对应的拼音
function getChineseSpell ($num, $blank = "") {
  if ( $num>0 && $num<160 ) {
   return chr($num);
  } elseif ($num<-20319||$num>-10247) {
   return $blank;
  } else {
   foreach (chineseSpellList as $spell => $code) {
    if ($code > $num) break;
    $result = $spell;
   }
   return $result;
  }
 }

//功能,取汉字第一个拼音
function getFirstSpell($chinese, $length = 0) {
  $spell =getChineseSpells($chinese, " ", 1);
  if ($length) {
   $spell = substr($spell, 0, $length);
  }
  return $spell;
 }
/*

*/

本文来源:http://www.bbyears.com/jiaocheng/25116.html

猜你感兴趣

热门标签

更多>>

本类排行