2

Here is my existing code from a previous question:

<?php 
@ini_set("output_buffering", "Off");
@ini_set('implicit_flush', 1);
@ini_set('zlib.output_compression', 0);
@ini_set('max_execution_time',1200);


header( 'Content-type: text/html; charset=utf-8' );


echo "Testing time out in seconds\n";
for ($i = 0; $i < 10; $i++) {
    echo $i." -- ";

    if(sleep(1)!=0)
    {
        echo "sleep failed script terminating"; 
        break;
    }
    flush();
    ob_flush();
}

?>

I want to now rewrite the previous number each loop, so that every second the number increases, like a timer. How would I go about doing this?

Thanks in advance.

Ryan
  • 105
  • 4
  • 14
  • 1
    You can't do that in HTML. You should be using Javascript to update the DOM. – Barmar Jun 01 '17 at 14:01
  • Php runs on the server. When ALL code has been run the browser gets a HTML to load. So doing what you ask is not a php question – Andreas Jun 01 '17 at 14:03

1 Answers1

0

The execution of PHP happens on the server side and the output is passed to your browser as HTML. Once the DOM is ready and you see it in the browser you should edit it with JavaScript in case you want to update it. Theoretically you could also have the browser to fetch a new version of the HTML output every second but that is quite heavy comparing to editing DOM with JavaScript.

Generally speaking PHP is to process data on the server side, JavaScript is to process data on the browser.

quinz
  • 1,282
  • 4
  • 21
  • 33