一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

php curl、fopen、file_get_contents实例代码

时间:2010-06-18 编辑:简简单单 来源:一聚教程网

//php教程 curl实例

 代码如下 复制代码

session_write_close();

$pageurl = "http://www.111com.net/index.html";
curl_setopt($ch, curlopt_returntransfer, 1);
curl_setopt ($ch, curlopt_url, $pageurl );
$html = curl_exec ( $ch );
curl_close($ch);

//then you need to fix pathing to absolute
$search = "/(src|href|background)="[^:,^>,^"]*"/i";

preg_match_all ( $search, $html, $a_matches );

//php fopen实例

 代码如下 复制代码

$file = fopen("http://www.111com.net/","r"); //读取远程文件

$file = fopen("a.txt","r");//读取本地文件

//php file_get_contents

$homepage = file_get_contents('http://www.111com.net/'); //读取远程文本
echo $homepage;

 代码如下 复制代码
// <= php 5
$file = file_get_contents('./people.txt', true);
// > php 5
$file = file_get_contents('./people.txt', file_use_include_path); //打开本地文本

 

热门栏目