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
echo implode('<br />', array_slice(file('file/datum2.html'), 0, 6));
OR
echo implode('
', array_slice(file('file/datum2.html'), 0, 6));
<?
$file1 = "file/datum2.html";
$lines = file($file1);
$output = array_slice($lines, 0, 6, true);
foreach($output as $line_num => $line)
{
echo $line[$line_num];
echo "<br>";
}
test the code using array_slice with true and without true
<?php
$file1 = "file/datum2.html";
$lines = file($file1);
$i= 0;
foreach($lines as $line_num => $line){
$i++;
echo $line[$line_num];
echo "<br>";
if($i == 6) break;
}
?>
Try this, it should works
<?php
$file1 = "file/datum2.html";
$lines = file($file1);
$lines = explode(" ",$lines);
echo $lines[5];
?>