RE: [PHP] Text File open and display
| From: | Niklas Lampén | Date: | Mon, 03 Mar 2003 09:06:12 +0000 |
| Subject: | RE: [PHP] Text File open and display | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-137861@lists.php.net to get a copy of this message | ||
You get a file to an array of lines with file().
Example:
<?
$myFile = file("text_file.txt");
// Now $myFile is an array looking like
// [0] => "row 1";
// [1] => "row 2";
// [2] => "row 3";
// .....
for ($i = 0; $i < count($myFile); $i++)
{
print "Row ".($i+1).": ".$myFile[$i];
};
?>
Niklas
-----Original Message-----
From: Chris Blake [mailto:cblake@pbpc.co.za]
Sent: 3. maaliskuuta 2003 10:58
To: php-general@lists.php.net
Subject: [PHP] Text File open and display
Greetings learned PHP(eople),
There have been a number of postings recently on opening and reading files,
and whilst I have read `em all I fail to make sense of it all.
Basicaly...I have a text file with entries in it...I wish to display the
contents of this file line by line in an HTML table : At present all I get
is a table with 1 row and all the text in it in a large messy blob.....
=====================================================================
<html>
<body>
<?php
$handle = fopen("fopen.txt","r");
echo '<table border="1"'."\n";
echo ' <tr>'."\n";
echo ' <td width="15%"><b>File
Entries</b></td>'."\n";
echo ' </tr>'."\n"."\n";
//----------------------------------------
//For each line in the file--------
// while (fpassthru($handle));
//{
//Print them out to Table-----------------
echo ' <tr>'."\n";
echo ' <td width="15%"><font size="2">';
echo fpassthru($handle);
echo '</td></tr>'. "\n";
//}
echo '</table>';
//fclose($handle);
?>
</body>
</html>
=================================================
I have commented out those lines which fail and am stuck as to what the
correct syntax should be. I have read up on nl2br,fgets and other posts on
php.net, but ......harumphhhhhhhh....
Thanks
--
Chris Blake
Office : (011) 782-0840
Cell : 083 985 0379
It is reported that somewhere in the world, every 15 seconds, a woman gives
birth to a child. She must be found and stopped.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
###########################################
This message has been scanned by F-Secure Anti-Virus for Internet Mail. For
more information, connect to http://www.F-Secure.com/
###########################################
This message has been scanned by F-Secure Anti-Virus for Internet Mail.
For more information, connect to http://www.F-Secure.com/