This is a little silly, but something I’ve wanted to do before and could never figure out. I have a PHP script that runs from the command line. I’d like a little timer animation to let the user know the script is still running. Here’s what I have:
while (1 == 1) {
echo '—';
usleep(100000);
echo '\';
usleep(100000);
echo '|';
usleep(100000);
echo '/';
}
But how do I get each echo to replace the character before it?
You need to print a backspace before each character, for example:-
Note that you have to use double quotes here or the escape sequence won’t work.
I’m sure you can work the rest out 🙂
If “\b” doesn’t work try:-