zeeshan_haider000 Posted January 6, 2010 Share Posted January 6, 2010 Hi, I have a text file such as: Tab1a||Tab2a||Tab3a Tab1b||Tab2b||Tab3b Now when i display this data, i want to display the line number next to it (i.e. Tab1b... line 2) How would i do that? Thanks Quote Link to comment Share on other sites More sharing options...
teamatomic Posted January 6, 2010 Share Posted January 6, 2010 http://php.net/manual/en/function.file.php HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
eawf Posted January 6, 2010 Share Posted January 6, 2010 Hi, I have a text file such as: Tab1a||Tab2a||Tab3a Tab1b||Tab2b||Tab3b Now when i display this data, i want to display the line number next to it (i.e. Tab1b... line 2) How would i do that? Thanks One way would be: $rows = @file("/path/to/filename.ext"); foreach($rows as $key=>$value){ $row = $key+1; echo $value." line ".$row."<br />"; } Quote Link to comment Share on other sites More sharing options...
zeeshan_haider000 Posted January 6, 2010 Author Share Posted January 6, 2010 Thanks for replying guys, I was asking the wrong question, here is my code... $file = file($file); $linenum = count($file); foreach($file as $line){ $tabs = explode('||', $line); /* Get the total lines in the file */ $no = count($tabs); for ($i = 0; $i < $no; $i++){ echo $tabs[$i].$linenum.'<br/>'; } instead of echoing $linenum, i was echoing $i... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.