I know PHP is usually used for web development, where there is no standard input, but PHP claims to be usable as a general-purpose scripting language, if you do follow it's funky web-based conventions. I know that PHP prints to stdout
(or whatever you want to call it) with print
and echo
, which is simple enough, but I'm wondering how a PHP script might get input from stdin
(specifically with fgetc()
, but any input function is good), or is this even possible?
views:
1427answers:
3You could also use the predefined constant STDIN instead of opening it manually: $line = fgets(STDIN);
gix
2009-02-16 22:26:57
STDIN did not work for me, but 'php://stdin', 'r' did. Using PHP 5.2.9-2 (cli) (built: Apr 9 2009 08:23:19) on Vista.
Eric J.
2009-10-26 20:09:34
+4
A:
IIRC, you may also use the following:
$in = fopen(STDIN, "r");
$out = fopen(STDOUT, "w");
Technically the same, but a little cleaner syntax-wise.
Fritz H
2009-02-16 23:09:29