The other day I was trying to print some output to the command line and then overwrite the output afterwards. It turns out that there are a couple of ways to do this so I thought I would detail a few of them here.
By far the simplest way of doing this is to run the "clear" command, which we can run via the system() function in PHP. This will clear the output of the command line ready for you to print out whatever you need. The downside to this is that the entire terminal window is cleared. Another downside is that once the output is complete scrolling up will reveal the output that was cleared out.