美文网首页
PHP函数 之 getopt

PHP函数 之 getopt

作者: Uchiha_Ponny | 来源:发表于2016-12-31 11:10 被阅读0次

函数作用:从命令行的参数列表中获取选项

函数格式:array getopt(string $options[, array $longopts])

参数解释:

  1. options:该字符串中的每个单个字符会被当做选项字符,匹配以单个-开头的选项,只允许a-z、A-Z、0-9
test.php
<?php
$options = getopt('a:b:cd:');
var_dump($options);
options
  1. longopts:该数组中的每个元素会被作为选项字符串,匹配以两个-开头的选项(--)
test_opt.php
<?php
$options = getopt('', ['class:', 'release:', 'limit', 'size:']);
var_dump($options);
longopts

注意点:

  1. 未在getopt函数中声明的选项,不会出现在结果中
  2. options 可能包含了以下元素:
    单独的字符(不接受值)
    后面跟随冒号的字符(此选项需要值)
    后面跟随两个冒号的字符(此选项的值可选)

相关文章

网友评论

      本文标题:PHP函数 之 getopt

      本文链接:https://www.haomeiwen.com/subject/upmvvttx.html