Entry
please tell me how to let a html document read content from a .txt file, spit this out in a table, and how to update the specific file with a form
Mar 15th, 2008 21:16
dman, ha mo, Articles Hosting, Cinley Rodick, Antonio Galea, bas debie, http://www.ttnr.org
To read a file into an array, use the 'file' function:
$lines=file('_file_name_here_');
then you iterate over $lines to collect what you need and build the
response.
An example:
--- file.txt ---
line1
line2
----------------
--- line_numbers.php ---
<?php
$lines=file('file.txt');
echo "<PRE>\n";
for($i=0;$i<count($lines);$i++){
echo "$i: ".$lines[$i];
}
echo "</PRE>\n";
?>
------------------------
To write to a file, you need the following syntax:
$fp=fopen('_filename_',"w"); //the open mode could be different
//remember to check $fp
...
$s=fwrite($fp,"a string here"); //check $s
...
$s=fclose($fp); //check $s
Have a look also at flock() for implementing file locking.
=====
use php then rewrite it to .html