0

I am new to php so, I have made a php code which is explained below

echo("1");
// a code that erase the previous output
echo("2);

Output should be:- First 1 should be printed then 1 should be erased then 2 should be printed.

If this can be possible the please help.

I tried this but didn't work,

flush();

I also searched in Google, YouTube, stackoverflow but didn't work. Output should be only like this:- First 1 should be printed then 1 should be erased then 2 should be printed.

  • Take a look at this https://stackoverflow.com/questions/1057986/how-to-clear-previously-echoed-items-in-php – DarkIntaqt Dec 30 '22 at 10:15
  • I dont see why you tagged Javascript, please dont spam tags – RiggsFolly Dec 30 '22 at 10:31
  • 4
    Is the target for this a browser page or are you running this in the PHP CLI – RiggsFolly Dec 30 '22 at 10:32
  • If your echo is a part of HTTP server response - you can not 'erase' something. You can use output buffer as described in the link in the first comment though. If it's a CLI you still cannot.. well.. erase. But you can ask terminal to go to the start of a line and replace printed out data with spaces for example. Described [here](https://en.wikipedia.org/wiki/ANSI_escape_code). – Jared Dec 30 '22 at 10:55

1 Answers1

0

Try this:

 <html>
 <body>
 <?php
 ob_start();
 echo "1";
 ob_clean();
 echo "2";
 ob_end_flush();
 ?>
</body>
</html>
Anaswara
  • 48
  • 7