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 Link to comment https://forums.phpfreaks.com/topic/187364-get-line-number-text-file/ 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 Link to comment https://forums.phpfreaks.com/topic/187364-get-line-number-text-file/#findComment-989404 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 />"; } Link to comment https://forums.phpfreaks.com/topic/187364-get-line-number-text-file/#findComment-989409 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... Link to comment https://forums.phpfreaks.com/topic/187364-get-line-number-text-file/#findComment-989411 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.