ted_chou12 Posted December 23, 2006 Share Posted December 23, 2006 this is my code:[code]<?php$contentsarray = file('content.html');foreach($contentsarray as $v) {$list = list($title,$datetime,$message) = explode(";seDp#",$v); echo '<a name="'. $title .'"></a><h1>'. $title. '</h1><p>'. $message .'</p><p class="post-footer align-right"><a href="index.html" class="readmore">Read more</a><a href="index.html" class="comments">Comments (7)</a><span class="date">'. $datetime .'</span></p>' . "\r\n";}?>[/code]however, i wish to get the line number of which the code is reading, is there a possible way to do that???? Link to comment https://forums.phpfreaks.com/topic/31717-solved-line-number-of-the-text-file-data/ Share on other sites More sharing options...
trq Posted December 23, 2006 Share Posted December 23, 2006 In this code, $line contains the line number.[code]<?php $contentsarray = file('content.html'); $line = 1; foreach($contentsarray as $v) { $list = list($title,$datetime,$message) = explode(";seDp#",$v); echo ' <a name="'. $title .'"></a> <h1>'. $title. '</h1> <p>'. $message .'</p> <p class="post-footer align-right"> <a href="index.html" class="readmore">Read more</a> <a href="index.html" class="comments">Comments (7)</a> <span class="date">'. $datetime .'</span> </p>' . "\r\n"; $line++; }?>[/code] Link to comment https://forums.phpfreaks.com/topic/31717-solved-line-number-of-the-text-file-data/#findComment-147091 Share on other sites More sharing options...
ted_chou12 Posted December 24, 2006 Author Share Posted December 24, 2006 thanks :) Link to comment https://forums.phpfreaks.com/topic/31717-solved-line-number-of-the-text-file-data/#findComment-147216 Share on other sites More sharing options...
trq Posted December 24, 2006 Share Posted December 24, 2006 Or if you want the total number of lines.[code=php:0]$contentsarray = file('content.html');$total = count($contentsarray);[/code] Link to comment https://forums.phpfreaks.com/topic/31717-solved-line-number-of-the-text-file-data/#findComment-147230 Share on other sites More sharing options...
ted_chou12 Posted December 24, 2006 Author Share Posted December 24, 2006 is count() a function? Link to comment https://forums.phpfreaks.com/topic/31717-solved-line-number-of-the-text-file-data/#findComment-147231 Share on other sites More sharing options...
corbin Posted December 24, 2006 Share Posted December 24, 2006 Yes, it counts the number of keys in an array. http://php.net/count Link to comment https://forums.phpfreaks.com/topic/31717-solved-line-number-of-the-text-file-data/#findComment-147237 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.