php中file_get_contents()函數用法實例

在本文中我們給大家整理了關於php中file_get_contents()函數的相關用法,需要的朋友們學習參考下。

我們先來看一下php中的 file_get_contents()函數的語法

string file_get_contents(string $ filename,bool $ include_path = false,resource $ context,int $ offset = 0,int $ maxlen)
  • filename是文件或URL的名稱。
  • include_path如果啓用,則在include_path中搜索文件
  • context這是用於修改流的行爲的選項集
  • offset此值指定要讀取的文件的起始位置。
  • maxlen此值指定要讀取的字節數。

將文件內容讀取爲字符串

這個php示例將從文件中讀取內容並存儲到字符串變量中。

<?php 
 $ content = file_get_contents(“input.txt”); 
 echo $ content; 
?>

將內容從URL讀取到字符串

<?php
 $content = file_get_contents("http://example.com");
 echo $content;
?>

以上就是關於php中file_get_contents()函數的相關知識點,感謝大家的閱讀和對神馬文庫的支持。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章