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

首頁 > 語言 > PHP > 正文

file_get_contents實現數據Post數據方法

2024-09-04 11:48:37
字體:
來源:轉載
供稿:網友

file_get_contents() 函數把整個文件讀入一個字符串中,和 file() 一樣,不同的是 file_get_contents() 把文件讀入一個字符串.

file_get_contents() 函數是用于將文件的內容讀入到一個字符串中的首選方法,如果操作系統支持,還會使用內存映射技術來增強性能.

語法:file_get_contents(path,include_path,context,start,max_length)

參數 描述 

path 必需。規定要讀取的文件.

include_path 可選,如果也想在 include_path 中搜尋文件的話,可以將該參數設為 "1".

context 可選,規定文件句柄的環境.

context 是一套可以修改流的行為的選項,若使用 null,則忽略.

start 可選,規定在文件中開始讀取的位置,該參數是 php教程 5.1 新加的.

max_length 可選,規定讀取的字節數,該參數是 php 5.1 新加的.

php實例代碼如下:

  1. <?php   
  2. function post($url$post = null)   
  3. {   
  4.     $context = array();   
  5.    
  6.     if (is_array($post))   
  7.     {   
  8.         ksort($post);   
  9.    
  10.         $context['http'] = array   
  11.         (   
  12.             'method' => 'post',   
  13.             'content' => http_build_query($post'''&'),   
  14.         );   
  15.     }   
  16.    
  17.     return file_get_contents($url, false, stream_context_create($context));  
  18. }   
  19.    
  20. $data = array   
  21. (   
  22.     'name' => 'test',   
  23.     'email' => 'test@gmail.com',   
  24.     'submit' => 'submit',   
  25. );   
  26.    
  27. echo post('http://localhost/5-5/request_post_result.php'$data);   
  28. ?> 

接收數據,request_post_result.php 接收經過post的數據,php代碼如下:

  1. <?php   
  2. echo $_post['name'];   
  3. echo $_post['email'];   
  4. echo $_post['submit'];   
  5. echo "fdfd";   
  6. ?> 

實例二,代碼如下:

  1. /**  
  2. * 其它版本  
  3. * 使用方法:  
  4. * $post_string = "app=request&version=beta";  
  5. * request_by_other('http://facebook.cn/restserver.php',$post_string);  
  6. */  
  7. function request_by_other($remote_server,$post_string){  
  8.     $context = array(  
  9.         'http'=>array(  
  10.             'method'=>'post',  
  11.             'header'=>'content-type: application/x-www-form-urlencoded'."rn".  
  12.                       'user-agent : jimmy's post example beta'."rn".  
  13.                       'content-length: '.strlen($post_string)+8,  
  14.             'content'=>'mypost='.$post_string)  
  15.         );  
  16.     $stream_context = stream_context_create($context);  
  17.     $data = file_get_contents($remote_server,false,$stream_context);  
  18.     return $data;  

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 拜泉县| 登封市| 离岛区| 安康市| 廊坊市| 邹平县| 阿坝县| 裕民县| 永城市| 陇西县| 慈利县| 洱源县| 金溪县| 城口县| 海晏县| 页游| 惠来县| 海丰县| 枣阳市| 秭归县| 翁牛特旗| 慈溪市| 抚宁县| 岢岚县| 宁化县| 恭城| 柘城县| 延庆县| 桂平市| 洪江市| 康保县| 梅河口市| 青龙| 文水县| 绥化市| 益阳市| 兴义市| 东乡县| 宽甸| 汝城县| 上蔡县|