Page 1 of 1

Read column until EoF

Posted: Wed Dec 16, 2009 1:19 pm
by jboku
Hey Guys,

I am a little new to PHP and I was wondering, I have a txt file with the following format:

Anniversary First Last name.

I basically want to write a PHP script that will grab the first column from the file (anniversary) and validate it against the current date and out put how long you've been there.

I know how to get todays date and validate it against another, but I don't know how to read it from the first column of the file. Can someone help?

Thanks

Re: Read column until EoF

Posted: Wed Dec 16, 2009 1:38 pm
by AbraCadaver
Assuming you don't have spaces in the dates, this should get you started:

Code: Select all

$lines = file('yourfile.txt', FILE_SKIP_EMPTY_LINES);
 
foreach($lines as $line) {
    $cols = explode(' ', $line);
    echo $cols[0];
}