如果页面是gbk的编码则转换为utf-8的如果是utf-8的则不转换,如何实现啊

解决方案 »

  1.   

    转码方式有很多种,我说下我实现转码的方法:文件用记事本打开,找到<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><link rel="alternate" type="application/rss+xml" href="http://www.fytpjy.cn/feed/" />
    ,这里修改utf-8修改成gb2312,然后另存为选择下面的编码格式为ANSI即可。反之亦然,另存为选择编码格式选择为utf-8即可。
      

  2.   

    我发现用iconv这个函数如果要将gbk的转为utf8的没问题,遇到utf8的就会出错啊
    这是我的代码:
    $webinfo = array();
    //$webinfo[0]["typelink"] = "http://www.renren.com";
    $webinfo[0]["typelink"] = "http://kx.hinews.cn";
    function GetKeywords($webinfo)
    {
    //$webinfo需要操作的数组
    $result = array();//存放返回结果的二维数组

    for($i=0;$i<count($webinfo);$i++)
    {                    preg_match("/(<meta .*)(keywords)(.*)(content\S\S)(.*)(\")(.*)(>)/i",$getstr,$matches);

    //将有用的信息存入数组
    $result[$i]["keywords"] = $matches[5];
    $result[$i]["typelink"] = $webinfo[$i]["typelink"];

    print_r($result);
    }
    //return $result;
    }
    print_r(GetKeywords($webinfo));

      

  3.   

    那是必然的!
    你把 utf-8 当做 gbk 转换成 utf-8 那还有的好吗?iconv 函数组没有提供字符集检测函数,你个以使用 mb 函数组
    $s = '中文';
    if(! mb_check_encoding($s, 'utf-8'))
      $s = mb_convert_encoding($s, 'utf-8', 'gbk');或
    mb_internal_encoding('utf-8');
    if(! mb_check_encoding($s)) $s = mb_convert_encoding($s, 'utf-8', 'gbk');