note 40405 deleted from function.readline by hholzgra
| From: | hholzgra@php.net | Date: | Thu, 02 Aug 2012 12:38:49 +0000 |
| Subject: | note 40405 deleted from function.readline by hholzgra | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189687@lists.php.net to get a copy of this message | ||
Note Submitter: TheFatherMind At Dangerous-Minds.NET
----
Above I took what "christian at gaeking dot de" did and I upgraded it a bit. Rewrote it
to my needs in the process. I found one minor bug with what he was doing and I also improved on
it....
The bug with what he had is that when you hit the keyboard "Return" key it takes that with
the varible. So if you type in 123 it takes "123\n". I needed to detect blank input so
I purge off the "\n" on the end to fix it.
The Enhancement. I added some options to the "read". One is that if you optionally
specify True for the second option on the ReadText function, it will NOT show what you type. This
is good for grabbing passwords. Also I added -er to the options of "read".
"-e" allows for standard input coming from the terminal (I use this for shell scripts).
Also "-r" turns off the backslash incase you want that as part of your input. This means
you can not escape any thing while doing input. Feel free to change the options though. And
finally I added the ability to prompt with the input.
<?php
Function ReadText($Prompt,$Silent=False){
$Options="-er";
If($Silent==True){
$Options=$Options." -s";
}
$Returned=POpen("read $Options -p \"$Prompt\"; echo \$REPLY","r");
$TextEntered=FGets($Returned,100);
PClose($Returned);
$TextEntered=SubStr($TextEntered,0,StrLen($TextEntered)-1-1);
If($Silent==True){
Print "\n";
@OB_Flush();
Flush();
}
Return $TextEntered;
}
?>