如何使用流删除字符串的最后一个符号

问题描述

我有一个用于终端的简单代码。按下退格键时,我可以显示书面命令,但无法删除符号。

<?PHP
...
        while($this->isRunned) {
            $read = [STDIN];
            $write = null;
            $except = null;
            $streamCounts = stream_select($read,$write,$except,null);
            if ($streamCounts) {
                $string = fgetc(STDIN);
                $symbol = substr($string,-1);
                if (ord($symbol) === 9) { //tab

                } elseif(ord($symbol) === 127) { //backspace
                    $string = substr($string,-1);
                }
                fputs(STDOUT,$string);
            }
        }
...

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)