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

How to pass parameters in php execution script

(*-*)浩
Release: 2023-02-23 16:32:01
Original
3638 people have browsed it

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);
Copy after login

Use getopt function

<?php
/**
 * 使用 getopt函数
 */
 
$param_arr = getopt(&#39;a:b:&#39;);
print_r($param_arr);
Copy after login

Prompt user for input

<?php
/**
 * 提示用户输入,类似Python
 */
fwrite(STDOUT,&#39;请输入您的博客名:&#39;);
echo &#39;您输入的信息是:&#39;.fgets(STDIN);
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template