0

I think this is probably a fairly original question. I'm new to php, and as practice to get comfortable with the language, Im working on a terminal like "hacker vs security" game. It's a pretty easy layout, and I'm looking forward to the possibilities, but I'd like to echo a dash (-) that flashes in front the "command line." Is this even possible: here is my current attempt:

    <?php
    $dash = "-";
    $space = " ";
    $int = 1;


    if ($odd == $int % 2)
    {
    $od_ev = 2;
    $int++;
    }
    else
    {
    $od_ev =3;
    $int++;
    }


    while ($od_ev == 2)
    {
    echo $dash;
    }

    ?>

Edit: a while, else capability in php would work nicely here, allowing an:

    else
    {
    Echo $space
    }
4

1 回答 1

0

假设您想使用 PHP CLI,以下应该可以工作:

在破折号/空格之后输出 a "\r",以便将光标设置为行首并覆盖最后一个输出。你应该使用下面的代码或类似的东西:

<?php
$char[0] = "-";
$char[1] = " ";
$int = 1;

while(1){
    $c = $int % 2;
    echo $char[c] . "\r";
    $int++;
    sleep(100); //that the user has a chance to see the flashing, time to wait in milliseconds
}

您的代码只需将 $od_ev 设置为 3 并将 $int 加一然后停止。

于 2013-02-15T19:22:14.283 回答