首 页 | 精品电影 | 音乐天堂 | 在线游戏 | Flash MTV | 三湘书屋 | 幽默笑话 | 三湘图库 | 美女写真 | IT知识库 | QQ贴图 | 加入书签

网页制作网络编程图形图象操作系统冲浪宝典软件教学网络安全认证考试通信技术电子商务业内动态书籍教程原码

最近更新 文章分类 多媒体类 精品软件

本站搜索:
您的位置:三湘时空 -> IT知识库 -> 文章分类 -> PHP实例 -> 简体中文转换为繁体中文的PHP函数  
简体中文转换为繁体中文的PHP函数


文章类别:PHP实例 来源: 作者: 发表日期:2005-10-3 字体:[ ]

小游戏 | 在线影院 | 幽默笑话 | 源码下载 | Flash MTV | 音乐试听 | 书屋 | 美女写真

感谢网友Keyes提供移植用的Delphi源代码。其调用方式为$txt=gbtobig5($txt)。
    (注:源代码中的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);
};
?>  

【本文版权归作者与奥索网共同拥有,如需转载,请注明作者及出处】    
上一篇:繁体中文转换为简体中文的PHP函数 下一篇:SQL Server里面的时间变更周期
本栏目热门文章
·用libTemplate实现静态网页的生成 2005-10-4
·如何把PHP转成EXE文件 2005-10-4
·php,不用COM,生成excel文件 2005-10-4
·一个简单的php在线端口扫描器 2005-10-4
·用PHP和MYSQL建立计数器过程详解 2005-10-4
·用PHP构建一个留言本 2005-10-4
·PHP自动生成月历代码 2005-10-4
·基于PHP+MySQL的聊天室设计 2005-10-4
·PHP百行代码快速构建简易聊天室 2005-10-4
·xml+php动态载入与分页 2005-10-4
新近更新文章
·用PHPdig打造属于你自己的Google 2006-2-23
·FC4下安装plog快速指南(plog版本:1.01) 2005-10-4
·PHP百行代码快速构建简易聊天室 2005-10-4
·一个简单的php在线端口扫描器 2005-10-4
·利用Yahoo! Search API开发自已的搜索引擎-php版 2005-10-4
·用PHP实现标准的IP Whois查询 2005-10-4
·用PHP和MYSQL建立计数器过程详解 2005-10-4
·使用MaxMind 根据IP地址对访问者定位 2005-10-4
·用PHP编程开发“虚拟域名”系统 2005-10-4
·使用PHP维护文件系统 2005-10-4
首 页 | 软件发布 | 广告联系 | 下载帮助 | 意见反馈 | 网站地图
  CopyRight? 2002-2004 WWW.SXSKY.NET? All Rights Reserved
三湘时空 站长QQ:82675303 Email: