I was looking for a way to interactively get a single character response from user. Using STDIN with fread, fgets and such will only work after pressing enter. So I came up with this instead:
#!/usr/bin/php -q
<?php
function inKey($vals) {
$inKey = "";
While(!in_array($inKey,$vals)) {
$inKey = trim(`read -s -n1 valu;echo \$valu`);
}
return $inKey;
}
function echoAT($Row,$Col,$prompt="") {
echo "\033[".$Row.";".$Col."H".$prompt;
}
echoAT(10,10,"Opt : ");
$options = array("1","2","3","4","X");
$key = inKey($options);
echoAT(12,10,"Pressed : $key\n");
?>
Hope this helps someone.