PHP getopt函数

简介:这是PHP getopt函数的详细页面,介绍了和php,有关的知识、技巧、经验,和一些php源码等。

class='pingjiaF' frameborder='0' src='http://biancheng.dnbcw.info/pingjia.php?id=336873' scrolling='no'> 短参数
它返回一个包含命令行参数的数组。比如,要获得-a -b 和-c的值,可以这么做:

$arguments = getopt("a:b:c:");

可以用下面的方式运行脚本(有无空格是没有关系的,注意看第一个例子和第二个例子):

php test.php -a app -b bar -c car
OR
php test.php -aapp -bbar -ccar


print_r($arguments) 将返回:

Array
(
    [a] => app
    [b] => bar
    [c] => car
)


注意:
1.冒号是需要的
2.如果没有指明值,在数组里面就不会出现

还是刚才的例子:

php test.php -a app

print_r($arguments) :

Array
(
    [a] => app
)


关于长参数

早于php 5.3的版本,如果使用长参数(--name=value 或--name value),很可能会得到如下的错误信息:

PHP Warning:  getopt(): No support for long options in this build in ...

因此,如果php的版本早于5.3最好还是使用短参数。

“PHP getopt函数”的更多相关文章 》

爱J2EE关注Java迈克尔杰克逊视频站JSON在线工具

http://biancheng.dnbcw.info/php/336873.html pageNo:9

posted on 2011-11-13 09:40  圣者  阅读(243)  评论(0编辑  收藏  举报

导航