I have text files, with thousand of lines, and I want to make a php page where I can see them, and that it opens in the exact line where I want. I mean, the scrollbar must be in the line I want. The file is full open on a pre Tag, but the scroll bar must be in the line 'N'.
This the php to open the file:
echo "<pre >";
$file = $pathOfFile;
$contents = file_get_contents($file);
$lines = explode("<br>", $contents); // this is your array of words
foreach($lines as $word)
echo $word;
echo"</pre>";
My suggestion would be to prepend each entry with an anchor tag:
echo '<pr>';
$file = $pathOfFile;
$contents = $file_get_contents($file);
$lines = explode('<br>', $contents);
$i = 0;
foreach($lines as $word)
{
echo '<a name="' . $i . '"></a>' . $word . '<br>';
++$i;
}
echo '</pre>';
So your end html would like this:
<pre>
<a name="0"></a>Line 1<br>
<a name="1"></a>Line 2<br>
<a name="2"></a>Line 3</br>
...
<a name="500"></a>Line 500
</pre>
Then when you load the page, and want to scroll to a specific tag, use an anchor in the URL. For instance, if you want to go to line 500 of 700, go to: