Rewrote example using foreach instead of while/list. Expanded the comments.

See also file_get_contents() and include().


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@100095 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Philip Olson 2002-10-18 02:15:02 +00:00
parent 45f6127d4d
commit 4684dff065

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.3 $ -->
<!-- $Revision: 1.4 $ -->
<!-- splitted from ./en/functions/filesystem.xml, last change in rev 1.2 -->
<refentry id="function.file">
<refnamediv>
@ -37,14 +37,17 @@
<programlisting role="php">
<![CDATA[
<?php
// get a web page into an array and print it out
$fcontents = file ('http://www.example.com/');
while (list ($line_num, $line) = each ($fcontents)) {
echo "<b>Line $line_num:</b>; ", htmlspecialchars ($line), "<br>\n";
// Get a file into an array. In this example we'll go through HTTP to get
// the HTML source of a URL.
$lines = file ('http://www.example.com/');
// Loop through our array, show html source as html source; and line numbers too.
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br>\n";
}
// get a web page into a string
$fcontents = implode ('', file ('http://www.example.com/'));
// Another example, let's get a web page into a string. See also file_get_contents().
$html = implode ('', file ('http://www.example.com/'));
?>
]]>
</programlisting>
@ -61,7 +64,8 @@ $fcontents = implode ('', file ('http://www.example.com/'));
<para>
See also <function>readfile</function>,
<function>fopen</function>, <function>fsockopen</function>, and
<function>popen</function>.
<function>popen</function>, and <function>file_get_contents</function>,
and <function>include</function>.
</para>
</refsect1>
</refentry>