首页 » SEO优化 » phpgetparameter用法技巧_PHP运用getopt解析cli参数

phpgetparameter用法技巧_PHP运用getopt解析cli参数

访客 2024-11-30 0

扫一扫用手机浏览

文章目录 [+]

广东IT优就业

广州IT培训老师讲一下,PHP利用getopt()解析cli参数。

phpgetparameter用法技巧_PHP运用getopt解析cli参数

PHP手册的getopt()先容如下:

/

Gets options from the command line argument list

@link http://php.net/manual/en/function.getopt.php

@param string $options Each character in this string will be used as option characters and

matched against options passed to the script starting with a single

hyphen (-).

For example, an option string \"大众x\"大众 recognizes an

option -x.

Only a-z, A-Z and 0-9 are allowed.

@param array $longopts [optional] An array of options. Each element in this array will be used as option

strings and matched against options passed to the script starting with

two hyphens (--).

For example, an longopts element \"大众opt\"大众 recognizes an

option --opt.

Prior to PHP5.3.0 this parameter was only available on few systems

@param int $optind If the optind parameter is present, then the index where argument parsing stopped will be written to this variable.

@return array This function will return an array of option / argument pairs or false on

failure.

@since 4.3.0

@since 5.0

/

function getopt ($options, array $longopts = null, &$optind = null) {}

$options :字符串类型,个中每个字符被当作选项字符,匹配传入脚本的选项以单个连字符(-)开头。
比如,一个选项字符串 \公众x\"大众 识别了一个选项 -x。
只许可 a-z、A-Z 和 0-9。

广东IT优就业

字符参数后面可以:

没有冒号(比如:h):不须要供应value,有供应也不会读取,用来判断有没有设置了这个参数。

有一个冒号(比如:p:):须要供应value,没有供应value就不读取这个参数。
可以按这几种办法来设置值:-p 123,–p123,-p=123。

有两个冒号(比如:f::):value是可选的,有没有设置value都读取(没有设置时读取的value为false),value须要连在参数后面,不能用空格分别隔。
可以按这几种办法来设置值:-f=123,-f123。

$longopts :数组类型,此数组中的每个元素会被作为选项字符串,匹配了以两个连字符(--)传入到脚本的选项。
例如,长选项元素 \公众opt\公众 识别了一个选项 --opt。

$options和$longopts的格式险些是一样的,唯一的不同之处是$longopts须要是选项的数组(每个元素为一个选项),而$options须要一个字符串(每个字符是个选项)。

希望广州IT培训老师本日禀享的内容对大家有所帮助。

广东IT优就业

出处:www.cnblogs.com/moxiaoping/p/8227836.html

更多IT精彩推举:

吸金能力者-PHP工程师:http://www.ujiuye.com/zt/php/?wt.mc_id=17009338

标签:

相关文章

我国土地利用分类代码的构建与应用

土地利用分类代码是我国土地管理的重要组成部分,是土地资源调查、规划、利用和保护的依据。土地利用分类代码的构建与应用显得尤为重要。本...

SEO优化 2025-02-18 阅读0 评论0

微信跳转微信支付便捷支付体验的秘密武器

移动支付已成为人们日常生活中不可或缺的一部分。作为我国领先的社交平台,微信支付凭借其便捷、安全的支付方式,深受广大用户的喜爱。而微...

SEO优化 2025-02-18 阅读0 评论0

探寻会计科目代码背后的奥秘分类与

会计科目代码是会计信息系统中不可或缺的组成部分,它将企业的经济活动进行分类和归纳,为会计核算、财务分析和决策提供重要依据。本文将从...

SEO优化 2025-02-18 阅读1 评论0