Jump to content


Photo

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


  • Please log in to reply
2 replies to this topic

#1 acroporas

acroporas
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 18 September 2006 - 12:02 AM

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?

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

        $firstline = file ( "$filename" );

        echo $firstline [0] ;
    }
?> 


#2 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 18 September 2006 - 12:06 AM

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

:-\
~ Mutley.

#3 acroporas

acroporas
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 18 September 2006 - 12:15 AM

Ok, you're right.  I feal so stupid.  All of my text files had the same first line.  Doh....




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users