utf-8和gbk编码的转换问题 如果页面是gbk的编码则转换为utf-8的如果是utf-8的则不转换,如何实现啊 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 转码方式有很多种,我说下我实现转码的方法:文件用记事本打开,找到<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即可。 我发现用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)); 那是必然的!你把 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'); 为什么分页不对呢?在别的地方是对的。 我可以学PHP吗? preg_replace替换的问题 mysql 如何在SQL语句里改变文本型字段的值 处理用户注册信息的简单代码(面向对象) 老大要走了。散分100 ceshi 函数和类的问题 判断一个字符在另一个串里存不存在的方法 关于安装appserv问题! 谁可以帮我写下,读取某个目录下的所有文件名的代码? thinkphp中,用mysql实现两表连接的查询语句。。求解
,这里修改utf-8修改成gb2312,然后另存为选择下面的编码格式为ANSI即可。反之亦然,另存为选择编码格式选择为utf-8即可。
这是我的代码:
$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));
你把 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');