牛骨文教育服务平台(让学习变的简单)
博文笔记

file_get_contents 输出乱码问题

创建时间:2016-12-29 投稿人: 浏览次数:3741
我的页面是utf-8,file_get_contents的页面是gb2312,输出时中文乱码。

解决方法如下:

<?php 
header("Content-Type:text/html;charset=utf-8"); 
$keyworld="煤层"; 
$keyworld=iconv("utf-8","gb2312",$keyworld); 
$url = "http://www.baidu.com/s?f=8&wd=$keyworld"; 
$html = file_get_contents($url); 
$html = iconv("gb2312", "utf-8//IGNORE",$html); 
echo $html;
?> 


声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。