Read column until EoF

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jboku
Forum Newbie
Posts: 10
Joined: Tue Nov 17, 2009 10:31 am

Read column until EoF

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Read column until EoF

Post 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];
}
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply