Home >Backend Development >PHP Problem >How to pass parameters in php execution script
Usually PHP makes HTTP requests, and you can use GET or POST to receive parameters. Sometimes you need to execute PHP as a script under a shell command, such as a scheduled task. This involves the issue of how to pass parameters to php under the shell command. There are usually three ways to pass parameters.
Use $argv or $argc parameters to receive (recommended learning: PHP video tutorial)
<?php /** * 使用 $argc $argv 接受参数 */ echo "接收到{$argc}个参数"; print_r($argv);
Use getopt function
<?php /** * 使用 getopt函数 */ $param_arr = getopt('a:b:'); print_r($param_arr);
Prompt user for input
<?php /** * 提示用户输入,类似Python */ fwrite(STDOUT,'请输入您的博客名:'); echo '您输入的信息是:'.fgets(STDIN);
The above is the detailed content of How to pass parameters in php execution script. For more information, please follow other related articles on the PHP Chinese website!