Perl作为Linux系统命令行脚本的首选解释语言的日子一去不复返了。今天,我们有了更多的选择,包括Python、Ruby和PHP。如果你已经为网站编写PHP代码,并熟谙这种语言,那么你会发现,在命令行使用PHP的速度之快,效果之好令人惊奇。
在脚本中,任何脚本语言的一个最大功用是对文件进行操作并获取用户输入。PHP处理这些丝毫不比其它任何脚本语言逊色。
例如,利用PHP在脚本执行期间处理读取用户提供输入,使用:
#!/usr/bin/php <?php function read_input() { $fp = fopen("/dev/stdin", "r"); $input = trim(fgets($fp, 255)); fclose($fp); return $input; }
printf("Please supply your name: "); $name = read_input(); printf("\nHello, $name.\n"); ?> </code>
(编辑:aniston)
|