note 10408 modified in function.fopen by irc-html
| From: | irc-html@php.net | Date: | Wed, 23 Jan 2002 23:38:21 +0000 |
| Subject: | note 10408 modified in function.fopen by irc-html | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-25761@lists.php.net to get a copy of this message | ||
Hi there! For anyone wondering how to use php for console scripts, here it goes a function that
reads stdin and works like good old Pascal Readln().
Hope it helps.
Paulo
<?
Function Readln(&$INPUT){
$fp = fopen("php://stdin","r");
while (!feof($fp)) {
$BUFFER = fgetc($fp);
$INPUT .= $BUFFER;
if ($BUFFER == "\n")
break;
}
fclose($fp);
}
echo "Enter something:";
Readln($UserInput);
echo "Input from console: ".$UserInput;
?>
--was--
Hi there! For anyone wondering how to use php for console scripts, here it goes a function that
reads stdin and works like good old Pascal Readln().
Hope it helps.
Paulo
<?
Function Readln(&$INPUT){
$fp = fopen("php://stdin","r");
while (!feof($fp)) {
$BUFFER = fgetc($fp);
$INPUT .= $BUFFER;
if ($BUFFER == "\n")
break;
}
fclose($fp);
}
echo "Enter something:";
Readln($UserInput);
echo "Input from console: ".$UserInput;
?>
http://www.php.net/manual/en/function.fopen.php