相似file_get_cotents()函数file()

array file ( string $filename [, int $use_include_path [, resource $context ]] )

file_get_contents() 同样,只除了 file() 将文件做为一个数组返回,而file_get_contents( )返回字符串。数组中的每一个单元都是文件中相应的一行,包括换行符在内。若是失败 file() 返回 FALSEphp

<?php
// 将一个文件读入数组。本例中经过 HTTP 从 URL 中取得 HTML 源文件。
$lines = file('http://www.example.com/');
// 在数组中循环,显示 HTML 的源文件并加上行号。
foreach ($lines as $line_num => $line) {
    echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";
}
// 另外一个例子将 web 页面读入字符串。参见 file_get_contents()。
$html = implode('', file ('http://www.example.com/'));
?>
相关文章
相关标签/搜索