更新命令行输出,即进度
我希望能够在命令行上用简单的 PHP 脚本显示进度表。 我不想只看到
Progress: 0%
Progress: 1%
etc...
要更改的数字,并替换以前的数字,就像 git clone 所做的那样,例如解决增量:100%(8522/8522),完成。
。
在搜索这个时,我发现 在 Perl 中回答了相同的问题,这是完美的,但我不能在 PHP 中找不到它。是否可以?如果没有,我将求助于 C。
谢谢
更新:如果有人对 C++ 版本感兴趣,它在这里。
I'd like to be able to show a progress meter in a simple PHP script on the command line. Instead of seeing
Progress: 0%
Progress: 1%
etc...
I'd like just the number to change, and replace the previous number, much like git clone does for example Resolving deltas: 100% (8522/8522), done.
.
While searching for this I found the same question answered in Perl, which is perfect, but I couldn't find it in PHP. Is it possible? If not, I'll resort to C.
Thanks
Update: If anyone's interested in the C++ version, it's here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可以使用 ANSI 转义序列来完成 - 参见此处 获取列表。
在 PHP 中,当页面上指示
ESC
时,您将使用"\033"
。在你的情况下,你可以使用这样的东西:
我简化了一点,确保我总是有 5 个额外的字符,并且始终显示相同数量的数据,总是向后移动相同数量的字符......
但是,当然,您应该能够做更复杂的事情,如果需要的话;-)
还有许多其他有趣的转义序列:例如,颜色可以大大增强你的输出;-)
This can be done using ANSI Escape Sequences -- see here for a list.
In PHP, you'll use
"\033"
when it's indicatedESC
on that page.In your case, you could use something like this :
I simplified a bit, making sure I always have 5 extra characters, and always displaying the same amount of data, to always move backwards by the same number of chars...
But, of course, you should be able to do much more complicated, if needed ;-)
And there are many other interesting escape sequences : colors, for instance, can enhance your output quite a bit ;-)
仅作为旧线程的记录:
我没有使用花哨的 ANSI 转义序列将光标移回原处,而是使用“\r”将其移回行首,而不是下一行“\n”的开头。在 echo 之后添加一些空格以覆盖之前存在的任何内容,例如:
Just for the record though an old thread:
Instead of using fancy ANSI Escape sequencing to move the curser back I just move it back to the beginning of the line using "\r" instead of to the beginning of the next line "\n". Add a few spaces after your echo to overwrite anything that was there previously, like e.g. so: