Advanced PHP Programming -- 如何理解 Console/Getopt.php 的使用 P129
来源:互联网 发布:信息可视化软件 编辑:程序博客网 时间:2024/06/08 18:58
开始没怎么理解short options 与 long options , 后来看了(http://pear.php.net/manual/en/package.console.console-getopt.examples.php)这个连接中的例子理解了。对“Console/Getopt.php”的了解也根据上面连接里的内容。
例子如下:
<?php/** * Example how to get a key-value pair array * from command line parameters with Console_Getopt. * * @link http://pear.php.net/bugs/bug.php?id=13902 */require_once 'Console/Getopt.php';/** * Make a key-value array. * Since Console_Getopt does not provide such a method, * we implement it ourselves. * * @params array $params Array of parameters from Console_Getopt::getopt2() * * @return array key-value pair array */function &condense_arguments($params){ $new_params = array(); foreach ($params[0] as $param) { $new_params[$param[0]] = $param[1]; } return $new_params;}$cg = new Console_Getopt();$args = $cg->readPHPArgv();array_shift($args);$shortOpts = 'u:g:';$longOpts = array('user=', 'group=');$params = $cg->getopt2($args, $shortOpts, $longOpts);if (PEAR::isError($params)) { echo 'Error: ' . $params->getMessage() . "\n"; exit(1);}var_dump(condense_arguments($params));/*When called as follows: associative.php -u jason -g argonautsyou will get this output: array(2) { ["u"]=> string(5) "jason" ["g"]=> string(9) "argonauts" } */?>
- Advanced PHP Programming -- 如何理解 Console/Getopt.php 的使用 P129
- Advanced PHP Programming -- "require_once(Console/getopt.php) : failed to open stream" P129
- Advanced PHP Programming -- 以键值对的形式取得命令行参数 (Console/Getopt.php 的使应用 P130)
- 《Advanced PHP Programming》读书笔记
- PHP and PostgreSQL: advanced Web programming
- php getopt
- PHP Console工具使用分享
- php+advanced
- PHP 中 getopt 函数的用法
- Programming PHP
- PHP programming
- 《PHP 程序设计》 Programming PHP
- 如何使用php的hashtable
- 114. PHP command line getopt
- 对php中函数使用的理解
- 如何理解php中的->符号
- php运行原理如何理解
- [PHP]如何使用PHP发送包含附件的电子邮件
- JAVA 内部类总结<1>
- 反应式AI,动手
- Android开发遇到Could not find class 'org.ksoap2.transport.HttpTransportSE'
- Delphi中的ParentBackground属性
- oracle database filesystem (DBFS) 简单配置文档
- Advanced PHP Programming -- 如何理解 Console/Getopt.php 的使用 P129
- 控制字符知识普及
- org.hibernate.Query 的setFirstResult(startRow) 和 setMaxResults(maxResult)
- Qt的4个图像类QImage/QPixmap/QBitmap/QPicture
- 在Windows 7中安装、配置和使用IIS7和ASP
- Myeclipse6或6.5反编译工具安装
- 分享一款超棒的jQuery Google地图插件:Gmaps
- 关于行状元素和块状元素【鸡蛋】
- 驱动SYS开发总结