Jump to content

Archived

This topic is now archived and is closed to further replies.

acroporas

Code not doing what I want it to. (very short)

Recommended Posts

I want to display the first line, from each .txt document in the folder.

But this code displays the first line of the first .txt document over and over.  Why?  How do I fix it?

[code]
<?php
    foreach (glob("*.txt") as $filename) {

        $firstline = file ( "$filename" );

        echo $firstline [0] ;
    }
?>
[/code]

Share this post


Link to post
Share on other sites
Just tested it and it works for me.

I made 2 .txt files one named "testme.txt" (first line "hello") other was "testme2.txt" (first line "yahoo").

It displayed:
hello yahoo

:-\

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.