點擊藍字關注我們!每天獲取最新的編程小知識!
源 / php中文網 源 / www.php.cn
php中的file_get_contents()函數是用於將文件內容讀入字符串的。此函數還能夠從URL讀取內容,下面 我們就來具體看看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教程》
http://www.php.cn/course/list/29.html
-END-
聲明:本文選自「 php中文網 」,搜索「 phpcnnew 」即可關注!