ホームページ  >  記事  >  php教程  >  php curl、fopen、file_get_contents实例代码

php curl、fopen、file_get_contents实例代码

WBOY
WBOYオリジナル
2016-05-25 16:42:191149ブラウズ

//php curl实例代码如下: 
 
session_write_close(); 
$pageurl = "http://www.phprm.com/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.phprm.com/","r"); //读取远程文件 
$file = fopen("a.txt","r");//读取本地文件 
//php file_get_contents 
$homepage = file_get_contents('http://www.phprm.com/'); //读取远程文本 
echo $homepage; 
: 
// <= php 5 
$file = file_get_contents(&#39;./people.txt&#39;, true); 
// > php 5 
$file = file_get_contents(&#39;./people.txt&#39;, file_use_include_path); //打开本地文本


本文地址:

转载随意,但请附上文章地址:-)

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。