例1
<?php
echo file_get_contents("test.txt");
?>
輸出:
This is a test file with test text.

 

例2
<?php
$homepage = file_get_contents('http://www.example.com/');
echo $homepage;
?>

例3
<?php
// <= PHP 5
$file = file_get_contents('./people.txt', true);
// > PHP 5
$file = file_get_contents('./people.txt', FILE_USE_INCLUDE_PATH);
?>

例4
<?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"

 

例5

<?php

//Using stream contexts
// Create a stream
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"Cookie: foo=bar\r\n"
)
);

$context = stream_context_create($opts);

// Open the file using the HTTP headers set above
$file = file_get_contents('http://www.example.com/', false, $context);
?>

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 stockwfj3 的頭像
    stockwfj3

    程式設計@筆記

    stockwfj3 發表在 痞客邦 留言(0) 人氣()