Clear PHP CLI output

Try outputting a line of text and terminating it with “\r” instead of “\n”.

The “\n” character is a line-feed which goes to the next line, but “\r” is just a return that sends the cursor back to position 0 on the same line.

So you can:

echo "1Done\r";
echo "2Done\r";
echo "3Done\r";

etc.

Make sure to output some spaces before the “\r” to clear the previous contents of the line.

[Edit] Optional: Interested in some history & background? Wikipedia has good articles on “\n” (line feed) and “\r” (carriage return)

Leave a Comment