php分享十五:php的命令行操作

一:像命令行传参数方法:

1: 使用$argc $argv

用法: /usr/local/php/bin/php ./getopt.php 123  456

 

2:使用getopt函数()

http://php.net/manual/zh/function.getopt.php

用法:运行 /usr/local/php/bin/php ./getopt.php -f 123 -g 456

$options = "f:g:";

$opts = getopt( $options );

print_r($opts);

 

3: 提示用户输入,然后获取输入的参数。有点像C语言
用法: 在命令行下运行 /usr/local/php/bin/php ./getopt.php

fwrite(STDOUT, "Enter your name: ");
$name = trim(fgets(STDIN));
fwrite(STDOUT, "Hello, $name!");

方法一 使用$argc $argv

posted @ 2016-01-19 19:38  一束光  阅读(205)  评论(0编辑  收藏  举报

友情链接

CFC4N