Home > php教程 > PHP源码 > body text

file_get_contents只读取网页的部分内容

WBOY
Release: 2016-06-08 17:27:18
Original
1427 people have browsed it

file_get_contents只读取网页的部分内容,其实这就是采集文章最简单最原始的做法了。

<script>ec(2);</script>

在php教程中

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

用法

file_get_contents( $url);

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

 代码如下 复制代码

$url = http://www.111cn.net

$content = file_get_contents( $url);

if( $content )

{

   $array = explode('

', $content);print_r($array); <p>}</p> <p>else</p> <p>{</p> <p>   echo '未采集成功';</p> <p>}</p> <p>//如果成功输出为</p> <p>array(</p> <p>0=>网页制作教程教程--网页设计教程网-提供专业网页设计与网页制作教程</p> <p>)</p>

好了就做完了。

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!