Jump to content

[SOLVED] line number of the text file data


ted_chou12

Recommended Posts

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

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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.