How can I implement echo output after some time on the site? Suppose one at once, and the second after 5 seconds. I tried to make the code lower, but the browser does not show anything for 5 seconds, and then both values ​​at once.

 <?php echo "1"; sleep(5); echo "2"; ?> 
  • The server issues a response 1 time when it prepares. For your task you need to use JS. If you need the answer from the server, then you need AJAX - Jurij Jazdanov

1 answer 1

You need to decide not using PHP tools but using jQuery or JavaScript

 <?php echo <<<HTML <p class="p1">1</p> <p class="p2" style="display:none">2</p> HTML; ?> 

 var timer; $(function(){ timer = setTimeout(function(){ $('.p2').show(); clearTimeout(timer); }, 5000); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <p class="p1">1</p> <p class="p2" style="display:none">2</p>