PHP 函數 file_get_contents 怎麼用?

2020-07-16 10:06:25

PHP 函數 file_get_contents 怎麼用?

在PHP中file_get_contents函數的作用是將整個檔案讀入一個字串,其語法為「file_get_contents($filename) 」,返回值為讀取出來的字元,使用方法只需將檔案路徑傳入$filename即可。

使用範例

<?php
$homepage = file_get_contents('http://www.example.com/');
echo $homepage;
?>
<?php
// <= PHP 5
$file = file_get_contents('./people.txt', true);
// > PHP 5
$file = file_get_contents('./people.txt', FILE_USE_INCLUDE_PATH);
?>
<?php
// Read 14 characters starting from the 21st character
$section = file_get_contents('./people.txt', NULL, NULL, 20, 14);
var_dump($section);
?>
string(14) "lle Bjori Ro"

推薦教學:《PHP

以上就是PHP 函數 file_get_contents 怎麼用?的詳細內容,更多請關注TW511.COM其它相關文章!