PHP CLI应用进阶
作者 : admin 于 2008-06-13 12:51:50
2008
06-13
06-13
上篇介绍了命令行参数的传递,参考php官方手册后,发现php的cli也是可以跟用户进行交互的。
http://cn.php.net/manual/en/features.commandline.php
To ease working in the shell environment, the following constants are defined:
| Constant | Description |
|---|---|
| STDIN |
An already opened stream to stdin. This saves opening it with <?php
If you want to read single line from stdin, you can use <?php |
| STDOUT |
An already opened stream to stdout. This saves opening it with <?php
|
| STDERR |
An already opened stream to stderr. This saves opening it with <?php
|
我比较倾向这种方式,这样就跟c++类似了
- <?php
- $line = trim(fgets(STDIN)); // reads one line from STDIN
- fscanf(STDIN, "%d\n", $number); // reads number from STDIN
- ?>