首页 > 开发 > PHP > 正文

php curl、fopen、file_get_contents实例代码

2024-05-04 21:58:33
字体:
来源:转载
供稿:网友
  1. //php curl实例代码如下: 
  2.  
  3. session_write_close(); 
  4. $pageurl = "http://www.Vevb.com/index.html";  
  5. curl_setopt($ch, curlopt_returntransfer, 1);  
  6. curl_setopt ($ch, curlopt_url, $pageurl );  
  7. $html = curl_exec ( $ch );  
  8. curl_close($ch); 
  9. //then you need to fix pathing to absolute  
  10. $search = "/(src|href|background)="[^:,^>,^"]*"/i"; 
  11. preg_match_all ( $search$html$a_matches ); 
  12.  
  13. //php fopen实例,代码如下: 
  14.  
  15. $file = fopen("http://www.Vevb.com/","r"); //读取远程文件 
  16. $file = fopen("a.txt","r");//读取本地文件 
  17. //php file_get_contents 
  18. $homepage = file_get_contents('http://www.Vevb.com/'); //读取远程文本 
  19. echo $homepage
  20. // <= php 5 
  21. $file = file_get_contents('./people.txt', true); 
  22. // > php 5 
  23. $file = file_get_contents('./people.txt', file_use_include_path); //打开本地文本 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表