首页 > php代码 > file_get_contents只读取网页的部分内容

file_get_contents只读取网页的部分内容

在php中

file_get_contents函数可以打开本地文件,也可能读取远程文件

用法

file_get_contents( $url);

下面我们来看一下file_get_contents采集远程网站的内容的实例

<?php
$url = 'http://www.phprm.com';
$content = file_get_contents( $url);
if( $content )
{
   $array = explode('<title>', $content);
   print_r($array);
}
else
{
   echo '未采集成功';
}

//如果成功输出为

array(

0=>网页制作教程教程--网页设计教程网-提供专业网页设计与网页制作教程

)

好了就做完了。

看看读取远程服务器内容的方法,可以和用fsockopen,fopen(需要设置allow_url_open)等函数来实现


教程链接:http://www.phprm.com/code/file_get_contents-server.html

随意转载~但请保留教程地址★

标签:none

发表留言