我试图使用php将输入插入命令行所以我做了什么,我有什么
我所拥有的我都有一个php代码,可通过comman行从客户那里读取输入当他通过cmd行运行php filename.php时它将要求他输入,然后单击Enter所以我想做的是我想从php中填充该行,当客户在3秒后没有填充它时,它会自动填充
所以这是代码
<?php
set_time_limit(0);
error_reporting(0);
class logincustom
{
public function readline($pesan)
{
echo "[Year Checker] " . $pesan;
$answer = rtrim(fgets(STDIN));
return $answer;
}
public function run()
{
$from = $this->readline("Year From : "); // this is what i wanna it to input from here if the customer did not input it after 3 second
$to = $this->readline("Year To : "); // this is what i wanna it to input from here if the customer did not input it after 3 second
if ($from > $to) die("Wrong number.");
for ($i = (int) $from; $i <= (int) $to; $i++) {
$year = sprintf("%03d", $i);
if ($year == 2026) {
echo "hello there";
} else {
// system(cls);
echo "wrong input \n\r" . exec(cls);
$this->run();
}
}
}
}
$logincustom = new logincustom;
$logincustom->run();
您可以使用strtotime()
功能