View Full Version : How to read lines from TXT file?

12-07-2010, 12:51 PM
I like to put tag clouds into my script like:
PHP Code:

<li class="tag1"><a href="#">Lorem ipsum</a></li>

How to read with PHP from defined path and its structure?
I enclose my TXT file with name tag terms. :)

12-07-2010, 02:44 PM
Use 'fgets' function to read text file line by line. Below is an example.

$handle = @fopen("/tmp/inputfile.txt", "r");
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle, 4096);
echo $buffer;

12-08-2010, 08:41 AM
You see structure? Is there mistake?

12-15-2010, 05:46 AM
Late, but spam lead me here.
Look into using fgetcsv to do this easily: http://php.ca/manual/en/function.fgetcsv.php. I don't know what all of your fields are for, but use a \t for your delimiter to chunk an array out of it. Other options include using things like *scanf family to separate it into chunks, or the strtok to tokenize it and suck the variables from the resulting strings.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum