首頁  >  文章  >  後端開發  >  如何使用php中的file_get_contents()函數將檔案內容讀入字串

如何使用php中的file_get_contents()函數將檔案內容讀入字串

不言
不言原創
2019-02-21 10:26:513875瀏覽

如何使用php中的file_get_contents()函數將檔案內容讀入字串中的file_get_contents()函數是用來將檔案內容讀入字串的。此函數也能夠從URL讀取內容,下面 我們就來具體看看如何使用php中的file_get_contents()函數將檔案內容讀入字串中的 file_get_contents()函數將檔案內容讀入字串的方法。

如何使用php中的file_get_contents()函數將檔案內容讀入字串

我們先來看看如何使用php中的file_get_contents()函數將檔案內容讀入字串中的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中的file_get_contents()函數將檔案內容讀入字串範例將從檔案讀取內容並儲存到字串變數中。

<?如何使用php中的file_get_contents()函數將檔案內容讀入字串 
  $ content = file_get_contents(“input.txt”); 
  echo $ content; 
?>

將內容從URL讀取到字串

<?如何使用php中的file_get_contents()函數將檔案內容讀入字串
  $content =  file_get_contents("http://example.com");
  echo $content;
?>

這篇文章到這裡就已經全部結束了,更多精彩內容大家可以關注如何使用php中的file_get_contents()函數將檔案內容讀入字串中文網的其他相關欄位教學! ! !

以上是如何使用php中的file_get_contents()函數將檔案內容讀入字串的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn