从带有变量的命令行运行php脚本 [英] Run php script from command line with variable
本文介绍了从带有变量的命令行运行php脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从命令行运行PHP脚本,但我也想为该脚本设置一个变量。
I want to run a PHP script from the command line, but I also want to set a variable for that script.
浏览器版本: script.php?var = 3
命令行: php -f script.php
推荐答案
脚本: / p>
Script:
<?php
// number of arguments passed to the script
var_dump($argc);
// the arguments as an array. first argument is always the script name
var_dump($argv);
命令:
$ php -f test.php foo bar baz
int(4)
array(4) {
[0]=>
string(8) "test.php"
[1]=>
string(3) "foo"
[2]=>
string(3) "bar"
[3]=>
string(3) "baz"
}
这篇关于从带有变量的命令行运行php脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文