Difference between revisions of "PHP:Read a Text File"

From Progzoo
Jump to navigation Jump to search
Line 3: Line 3:
 
<question lang="php" className="Demo" copyFile="haggis.txt"><prog><![CDATA[
 
<question lang="php" className="Demo" copyFile="haggis.txt"><prog><![CDATA[
 
<?
 
<?
open A, 'haggis.txt';
+
$fh = fopen('haggis.txt','r');
while (&lt;A&gt;){
+
while (!feof($fh)){
   chomp;
+
   $line = fgets($fh);
   print "$_\n";
+
   echo $line;
 
}
 
}
close A;
+
fclose($fh);
 
?>
 
?>
 
]]>
 
]]>

Revision as of 12:58, 31 December 2007

You can open a text file and read each line.

Reading lines

The text file [../haggis.txt haggis.txt] includes some lines of text.

[Font] [Default] [Show] [Resize] [History] [Profile]