PHP抓取网页方法

方法一:函数把整个文件读入一个数组中

<?php
$lines_array = file($url);
$lines_string = implode('', $lines_array);
eregi("(.*)", $lines_string, $head);
echo $head[0];
?>


方法二:函数把整个文件读入一个字符串中

代码
<?php
$num=file_get_contents('网址');
$num=str_replace("xxxx","yyyy",$num); //模板语言用生成的程序替换进去
eregi("<title>(.*)</title>", $num, $head); //得到从<title>到</title>之间的字符,并放到$head数组中
echo $head[0];
?>

 

posted @ 2010-07-06 19:12  ooyiye  阅读(139)  评论(0编辑  收藏  举报