gpt4 book ai didi

php - 使用变量从命令行运行 php 脚本

转载 作者:IT王子 更新时间:2023-10-28 23:55:31 25 4
gpt4 key购买 nike

我想从命令行运行 PHP 脚本,但我也想为该脚本设置一个变量。

浏览器版本:script.php?var=3

命令行:php -f script.php(但如何给它包含 3 的变量?)

最佳答案

脚本:

<?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"
}

另外,看看 using PHP from the command line .

关于php - 使用变量从命令行运行 php 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/974356/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com