提示:

1.怎么获取参数 $argc参数个数 $argv[]参数数组

2.getcwd()返回当前工作目录

 

设置一个需求:

写一个php脚本,god -v 显示当前版本, god -init在当前目录生成一个god.json文件,文件内容为一个大括号。

 

一切搞定后,显示这样两句话

1. xx of bytes written

2.God config is created


代码:

#!/usr/local/php/bin/php
<?php
if($argc>1){
$argv[1]=='-v' && $str='god version1.0'.PHP_EOL;
$argv[1]=='-init' && $str=file_put_contents(getcwd().'/'.'god.json','{}').'of bytes written'.PHP_EOL.'god config is created';
}
echo $str;
echo PHP_EOL;