John John - 3 months ago 18
PHP Question

Php - echo line 6 from Text file

How to echo line 6 from Text file?

I have tried this.
But i dont know what to do further. This is not working.
What to change?

<?
$file1 = "file/datum2.html";
$lines = file($file1);
foreach($lines as $line_num => $line)
{
echo $line[6];
echo "<br>";
}

?>


Datum2.html:

1-juli-2016
2-juli-2016
3-juli-2016
4-juli-2016
5-juli-2016
6-juli-2016

This is the result now with help

enter image description here

Answer
echo implode('<br />', array_slice(file('file/datum2.html'), 0, 6));

OR

echo implode('\n', array_slice(file('file/datum2.html'), 0, 6));
Comments