Home >Backend Development >PHP Problem >How to pass parameters in php execution script

How to pass parameters in php execution script

(*-*)浩
(*-*)浩Original
2019-09-05 10:17:433591browse

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.

How to pass parameters in php execution script

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(&#39;a:b:&#39;);
print_r($param_arr);

Prompt user for input

<?php
/**
 * 提示用户输入,类似Python
 */
fwrite(STDOUT,&#39;请输入您的博客名:&#39;);
echo &#39;您输入的信息是:&#39;.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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn