教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 file_get_contents只读取网页的部分内容

file_get_contents只读取网页的部分内容

发布时间:2016-10-27   编辑:jiaochengji.com
教程集为您提供file,get,contents只读取网页的部分内容等资源,欢迎您收藏本站,我们将为您提供最新的file,get,contents只读取网页的部分内容资源
file_get_contents只读取网页的部分内容,其实这就是采集文章最简单最原始的做法了。

在php教程中

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

用法

file_get_contents( $url);

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

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy6403')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy6403>

$url = http://www.jiaochengji.com

$content = file_get_contents( $url);

if( $content )

{

   $array = explode('<title>', $content);print_r($array);

}

else

{

   echo '未采集成功';

}

//如果成功输出为

array(

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

)

好了就做完了。

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

您可能感兴趣的文章:
file_get_contents只读取网页的部分内容
php读取远程文件的三种方法分享
php中curl、fsocket、file_get_content函数比较
PHP检测给定url是否是404页面的方法
php file_get_contents读取大容量文件方法
file_get_contents访问http取回响应头
php获取html网页内容的多个方法
PHP fopen/file_get_contents与curl性能比较
php利用file_get_contents批量采集网站内容
PHP 获取远程网页内容的代码

[关闭]
~ ~