建站软件 优化软件 编程软件 网页辅助 站群程序 网站程序 图像处理 资源教程 字体下载 推荐软件


您的位置:首页 > PHP学习 > php中文转繁体

php中文转繁体

时间:2015-02-15 10:24:23  来源:免费模板网 作者:风雪 阅读次数 tagsphp中文转繁体

有时候要用到繁体,在php里面怎么实现呢?请看下文

function isgb($code) 


  if (strlen($code)>=2) 
  { 
    $code=strtok($code,""); 
    if ((ord($code[0]) < 161)||(ord($code[0]) >= 247)) 
    { 
      return (0); 
    } 
    else 
    { 
      if ((ord($code[1]) <= 161)||(ord($code[1]) >= 254)) 
      { 
        return (0); 
      } 
      else 
      { 
        return (1); 
      } 
    } 
  } 
  else 
  { 
    return (1); 
  } 


function gboffset($code) 

  if (strlen($code) >= 2) 
  { 
    $code=strtok($code,""); 
    return ((ord($code[0]) - 161) * 94 + (ord($code[1]) - 161)); 
  } 
  else 
  { 
    return(-1); 
  } 


function wordtostring($code) 

  return (chr(hexdec(substr($code,0,2))).chr(hexdec(substr($code,2,2)))); 


function gbtobig5($code) 

  include "data_gb.php"; 
  $output=""; 
  $length=strlen($code); 
  $code=strtok($code,""); 
  $idx=0; 
  while ($idx < $length) 
  { 
    $tmpStr=$code[$idx].$code[$idx+1]; 

    if (isgb($tmpStr)) 
    { 
      $offset=gboffset($tmpStr); 
      if (($offset >= 0)||($offset <= 8177)) 
      { 
        $output.=wordtostring($gborder[$offset]); 
        $idx++; 
      } 
      else 
      { 
        $output.= $code[$idx]; 
      } 
    } 
    else 
    { 
      $output.= $code[$idx]; 
    } 
    $idx++; 
  } 
  return ($output); 
}; 
?>  

【本文版权归作者与奥索网共同拥有,如需转载,请注明作者及出处】    

本文地址:https://www.freemoban.com/php/2015/0215/577.html

猜你喜欢
栏目推荐
模板推荐

Copyright:www.freemoban.com 免费模板网 All Rights Reserved 网站备案:辽ICP备19014872号-2   辽公网安备 21010602000376号  辽公网安备:42900402000182号

免责声明:本站部分资源来自互联网收集,版权归原创者所有,如果侵犯了你的权益,我们会及时删除侵权内容,联系QQ:1615187561 谢谢合作!