我們先來看一下php中的 file_get_contents()函數(shù)的語法
string file_get_contents(string $ filename,bool $ include_path = false,resource $ context,int $ offset = 0,int $ maxlen)
- filename是文件或URL的名稱。
- include_path如果啟用,則在include_path中搜索文件
- context這是用于修改流的行為的選項(xiàng)集
- offset此值指定要讀取的文件的起始位置。
- maxlen此值指定要讀取的字節(jié)數(shù)。
將文件內(nèi)容讀取為字符串
這個php示例將從文件中讀取內(nèi)容并存儲到字符串變量中。
<?php $ content = file_get_contents(“input.txt”); echo $ content; ?>
將內(nèi)容從URL讀取到字符串
<?php $content = file_get_contents("http://example.com"); echo $content; ?>
以上就是關(guān)于php中file_get_contents()函數(shù)的相關(guān)知識點(diǎn),感謝大家的閱讀和對服務(wù)器之家的支持。