> I wonder if anyone could point in the direction of a good tutorial for
> using a delimited text file database with PHP?
> I do not have a real database available to me, but I don't think that
> will be a problem because my needs are extremely simple. This text file
> will be read-only, with probably no more than 30 or so lines. Each line
> will have six fields, delimited by a pipe ("|") character.
> There will be a single parameter passed in the URL indicating which line
> is needed. For example, foo.php?bar=1 means line 1 should be used. I will
> then need to display the contents of that line.
Should be pretty straight forward:
Let your data be stored in $data;
Open your file: fopen()
set your index counter to 0;
loop while not eof
reading one line at a time into a variable: fgets()
Strip the newline from it:
make an array out of it, breaking on the seperator character
add this array to your array of lines.
$data[$index++] = your line array
when done, close the file: fclose()
Remember though, PHP arrays start at a 0,
so your first line/first data is $data;
United Defense, San Jose
> I know how to open the file using fopen() and fread(), but I do not know
> how to anything with the data. I'm guessing I'll load the data into a
> multidimensional array. For example, $line would refer to the first
> field of the first line. Likewise, $line is the second field of
> line 15. I could then display the data by printing $line or
> whatever where needed. Is this correct?
> I've searched the web a bit but haven't come up with anything that really
> shows me how to do this. Any help would be greatly appreciated. Thanks.
> s/example.gov/mindspring.com to e-mail