0
点赞
收藏
分享

微信扫一扫

php小偷程序--获取网站内容

php如何抓取网站内容?

以获取网站title为例子:

<?php 
function getTitle($url){
$filecnt=file_get_contents($url);
$wcharset = preg_match("/<meta.+?charset=[^\w]?([-\w]+)/i",$filecnt,$temp) ? strtolower($temp[1]):"";
$wtitle = preg_match("/<title>(.*)<\/title>/isU",$filecnt,$temp) ? $temp[1]:"";
$str=null;
$str=iconv($wcharset,'utf-8',$wtitle);
$result='网页文件编码为:'.$wcharset.'<br>网页标题为:'.$str;
return $result;
}
$url="http://www.baidu.com";
echo getTitle($url);
?>

输出结果为:

网页文件编码为:utf-8
网页标题为:百度一下,你就知道


举报

相关推荐

0 条评论