Skip one line?

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
Burton333
Forum Newbie
Posts: 15
Joined: Wed Apr 01, 2009 7:04 pm

Skip one line?

Post by Burton333 »

pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


I'm trying to get the file into array strings, but then I just want to ignore/delete the first line which are the fields. Can someone help me?

Code: Select all

<?php
$lines = file('http://giraffe.uvm.edu/~rgweb/batch/curr_enroll_fall.txt');
 
// Loop through array
foreach ($lines as $line_num => $line) {
    echo $line . "<br />\n";
}
?>
My overall objective though is to use the information below the first line. I want to then split each thing using the split() function, and then place each variable accordingly into the database. Having this file consistently refresh in order to get the most accurate current information. Can someone please lead me in the right direction?


pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Skip one line?

Post by pickle »

array_shift() will get rid of the first row for you.

If this is a comma separated file, or some other format delimited by a common character, consider explode() instead of split(). Anything that uses regular expressions is costly (in terms of processor cycles) and should be avoided if at all possible.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Skip one line?

Post by McInfo »

If you need the first line to remain in the array, use continue.

Edit: This post was recovered from search engine cache.
Post Reply