doushi1974 2015-08-13 14:41
浏览 332

命令行PHP:混合fread(STDIN,...)和fgets(STDIN)的问题

I am working on a command-line-script witch uses fread (for yes/no,...) and fgets (for manually validating values,...).

The problem is if I enter more than ... chars ( is a char, too), this chars are already inputed in the next fgets/fread-function.

I tried fflush(STDIN), but it didn't work. I also tried stream_get_line(STDIN,1024); which was recommended by someone in a simmelar question, but then I have to input nearly unendless much chars until the programm continues (I quit).

How to get PHP to delete keyboard-buffer before using fgets/fread?

  • 写回答

1条回答 默认 最新

  • dongtanliefang8765 2015-08-13 15:10
    关注

    If your PHP is compiled with the Readline module (it's quite common) you may just use readline()

    http://php.net/manual/en/function.readline.php

    $input = readline( 'Prompt: ' );
    

    readline() simplifies the process of reading input from the terminal.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题