I am trying to write a HTML table to a webpage row by row instead of having it all appear after the whole page has processed.
I have read about and attempted to add ob_flush(), flush(), ob_start(); ob_implicit_flush(true); ob_end_flush();
but everything I have attempted has resulted in the the whole table appearing all at once so I am not sure if it is possible misplacement of the code, misunderstanding of the use, or a setting on my server.
ob_start();
$url = "http://www.example.com";
$html = file_get_contents($url);
$doc = new DOMDocument();
$doc->loadHTML($html);
$tags = $doc->getElementsByTagName('img');
echo "<table>
<th>Path</th>
<th>Alt</th>
<th>Height</th>
<th>Width</th>";
foreach ($tags as $tag){
$image = $tag->getAttribute('src');
$alt = $tag->getAttribute('alt');
$height = $tag->getAttribute('height');
$width = $tag->getAttribute('width');
echo "<tr>
<td>$image</td>
<td>$alt</td>
<td>$height</td>
<td>$width</td>
</tr>";
ob_flush();
flush();
}
echo "</table><br>";
ob_start();in the start of the file?flush()so that the table will show up bit by bit rather than all in one chunk after the processing is complete. This is desirable if you have an extremely long table as it gives the user some of the data without having to wait for all of it to render.