Forum Moderators: coopster

Message Too Old, No Replies

read data from txt file

read data from txt file

         

MrKool

6:55 pm on Jul 23, 2004 (gmt 0)

10+ Year Member



Hello,

I wanted the script which works as a catalogue page but in php and use txt file as a database .

Product name and description is stored in txt files

Result should be display as following
Product a
Product description

Product b
Product description

and so on

if pagination in this script is possible so it would be great.

The structure of a file will be like this

Product A, Product A description
Product B, Product B description


I hope you get my point. Looking for a positive answer

HughMungus

7:01 pm on Jul 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I was curious about this so I looked it up (and in the process found some info I've been looking for, myself).

Use a .csv file instead and use fgetcsv.

Found this example.

<?php
//stock quote script
//this is the url for Microsoft's stock quote , we are opening it for reading
$fp = fopen ("http://finance.yahoo.com/d/quotes.csv?s=msft&f=sl1d1t1c1ohgv&e=.csv","r");
//this uses the fgetcsv function to store the quote info in the array $data
$data = fgetcsv ($fp, 1000, ",")
?>
<!-- this is our table which displays the stock info -->
<!-- we access the individual items by using $data[0]-->
<table>
<tr><td>description</td><td>latest figure</td><tr>
<tr><td>symbol</td><td><?php echo $data[0]?></td></tr>
<tr><td>last price</td><td><?php echo $data[1]?></td></tr>
<tr><td>date</td><td><?php echo $data[2]?></td></tr>
<tr><td>time</td><td><?php echo $data[3]?></td></tr>
<tr><td>change</td><td><?php echo $data[4]?></td></tr>
<tr><td>open</td><td><?php echo $data[5]?></td></tr>
<tr><td>high</td><td><?php echo $data[6]?></td></tr>
<tr><td>low</td><td><?php echo $data[7]?></td></tr>
<tr><td>volume</td><td><?php echo $data[8]?></td></tr>
</table>
<?php
//close the filehandle $fp
fclose ($fp);
?>