<?php
$url = 'http://luolai.tmall.com/search.htm?pageNum=1';
$lines_array = file($url);
echo $lines_array; echo "<br/>"; $lines_string = implode('', $lines_array);
eregi("<title>(.*)</title>", $lines_string, $head);
echo "head:".$head;
echo "<br/>"; print_r($head);
echo "<br/>";
echo "title:".$head[1]; ?>
这个打印出来有乱码,如何才能不乱码?
$url = 'http://luolai.tmall.com/search.htm?pageNum=1';
$lines_array = file($url);
echo $lines_array; echo "<br/>"; $lines_string = implode('', $lines_array);
eregi("<title>(.*)</title>", $lines_string, $head);
echo "head:".$head;
echo "<br/>"; print_r($head);
echo "<br/>";
echo "title:".$head[1]; ?>
这个打印出来有乱码,如何才能不乱码?
解决方案 »
- 求一个正则!
- getJSON请求PHP数据问题
- 求救:帮忙写个curl登录获得个人信息的代码!十万火急~
- 如何通过技术来优化网站?
- 如何让php将数据库存的字段显示出来?
- 请教一个异常:Your script possibly relies on a session side-effect which ...
- php类的成员变量没有声明
- 哪位解决过 Php & sql server 2000 图片存储在数据库中和图片查询问题?
- 获取上一页面id
- 关于距离排序的问题
- phpMyAdmin如何让一张表里面的数字等于另外一张表中三个数字相加的总和并且可以动态更新?
- 报错Notice: Undefined offset: 1
function file_get_contents_utf8($fn) {
$content = file_get_contents($fn);
return mb_convert_encoding($content, 'UTF-8',
mb_detect_encoding($content, 'UTF-8, ISO-8859-1', true));
}
?>
echo "title:".iconv('gbk','utf-8',$head[1]);
所以在打印前应做编码转换
$head = iconv('gbk', 'utf-8', $head);
但结果还是有的
Array
(
[0] => <title>
宝贝列表页-罗莱家纺官方旗舰店-- 天猫Tmall.com </title>
[1] =>
宝贝列表页-罗莱家纺官方旗舰店-- 天猫Tmall.com
)
<br/>title:
宝贝列表页-罗莱家纺官方旗舰店-- 天猫Tmall.com