【问题标题】:PHP progress bar for termuxtermux 的 PHP 进度条
【发布时间】:2021-04-26 09:06:27
【问题描述】:

这是termux的进度条代码:

<?php
$iloop = "0"; /* Outside the loop */
while (true){  
    $warn = "Program running  holdd on!!\r";
    if (strlen($warn) === $iloop+1){
        $iloop = "0";
    }
    $warn = str_split($warn);
    $iloop++;
    $warn[$iloop] = "\033[ 35;2m\e[0m".strtoupper($warn[$iloop]);
    echo "\033[7m".implode($warn);
    usleep(90000);
}

这不断重复。我希望它在 20 秒后停止,然后开始打印我剩余的代码。那么如何在 20 秒后停止呢?

【问题讨论】:

  • $iloop = "0"; 将其更改为 $iloop = 0; 因为在循环中您将 $iloop 加一所以它应该是 int 而不是 char

标签: php termux


【解决方案1】:
$iloop = 0; /* Outside the loop */
while (true){  
  $warn = "Program running  holdd on!!\r";
  if (strlen($warn) === $iloop+1){
    $iloop = 0;
  }
  $warn = str_split($warn);
  $iloop++;
  $warn[$iloop] = "\033[ 35;2m\e[0m".strtoupper($warn[$iloop]);
  echo "\033[7m".implode($warn);
  usleep(90000);
}

正如我在评论中提到的,您的 $iloop 变量包含 0 的字符串值,因此当它进入循环时它不会递增,因此只需将 $iloop='0' 更改为 $iloop=0

在这里阅读更多关于data types的信息,

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-19
    • 2012-03-07
    • 2016-04-24
    相关资源
    最近更新 更多