简体中文转换为繁体中文的PHP函数

来源:互联网 发布:淘宝提升排名方法 编辑:程序博客网 时间:2024/05/18 01:08
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
(注:源代码中的include "data_gb.PHP";这个文件在就是一个数组,在http://caocao.oso.com.cn/data_gb.zip,请编辑下载到oso上,做一个链接,因为这个文件我过几天就要删除了。)

<?
/***********************************************************************
                       Written by caocao
                       caocao@eastday.com
                       http://caocao.oso.com.cn
                        
                       With the help of Keyes
                       Keyes2000@263.net
                       http://my-wjl.scu.edu.cn/~Keyes
***********************************************************************/
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);
};
?>  

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>