国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

php 讀取文件函數(shù)

2024-09-04 11:48:58
字體:
供稿:網(wǎng)友

1、用file_get_contents或者fopen、file、readfile等函數(shù)讀取url的時(shí)候,會(huì)創(chuàng)建一個(gè)名為$http_response_header的變量來保存http響應(yīng)的報(bào)頭,使用fopen等函數(shù)打開的數(shù)據(jù)流信息可以用stream_get_meta_data來獲取.

2、php5中新增的參數(shù)context使這些函數(shù)更加靈活,通過它我們可以定制http請(qǐng)求,甚至post數(shù)據(jù).

示例代碼1,如下:

  1. <?php  
  2. $html = file_get_contents('http://www.survivalescaperooms.com);  
  3. print_r($http_response_header);   
  4. // or  
  5. $fp = fopen('http://www.example.com''r');  
  6. print_r(stream_get_meta_data($fp));  
  7. fclose($fp);  
  8. ?> 

示例代碼2,代碼如下:

  1. <?php  
  2. $data = array ('foo' => 'bar');  
  3. $data = http_build_query($data);  
  4. $opts = array (  
  5.     'http' => array (  
  6.         'method' => 'post',  
  7.         'header'=> "content-type: application/x-www-form-urlencoded " .  
  8.                    "content-length: " . strlen($data) . " ",  
  9.         'content' => $data  
  10.     ),  
  11. );  
  12. $context = stream_context_create($opts);  
  13. $html = file_get_contents('http://www.survivalescaperooms.com', false, $context);  
  14. echo $html;  
  15. ?> 

實(shí)例三

獲取過來以后自動(dòng)輸出到瀏覽器,我們有沒有其他的方式組織獲取的信息,然后控制其輸出的內(nèi)容呢?完全沒有問題,在curl_setopt()函數(shù)的參數(shù)中,如果希望獲得內(nèi)容但不輸出,使用curlopt_returntransfer 參數(shù),并設(shè)為非0值/true!,完整代碼請(qǐng)看:

  1. <?php?// create a new curl resource  $ch = curl_init();  // set url and other appropriate options  curl_setopt($ch, curlopt_url, “http://www.google.nl/”);  
  2.  curl_setopt($ch, curlopt_returntransfer, true);  // grab url, and return output  $output = curl_exec($ch);  // close curl resource, and free up system resources  curl_close($ch);  // replace ‘google’ with ‘phpit’  $output = str_replace(’google’,‘phpit’, $output);  // print output  echo $output;   
  3. //開源軟件:Vevb.com 
  4. ?>

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 安泽县| 治多县| 陈巴尔虎旗| 大厂| 正蓝旗| 乌拉特后旗| 宝兴县| 当涂县| 隆昌县| 格尔木市| 探索| 白水县| 宁强县| 万源市| 湘西| 台北县| 日土县| 项城市| 额济纳旗| 伊春市| 安顺市| 喀喇沁旗| 新野县| 彩票| 寿阳县| 南康市| 德令哈市| 曲周县| 衡阳市| 大理市| 嵊州市| 梁山县| 大荔县| 龙岩市| 林口县| 石屏县| 筠连县| 湖北省| 兴安盟| 东海县| 商河县|