Command line execution $argv and $argc configuration method in php script_php example

jacklove
Release: 2023-04-02 10:32:01
Original
3717 people have browsed it

This article mainly introduces the method of executing $argv and $argc in php scripts from the command line. This article introduces it to you in great detail. Friends who need it can refer to it.

It may be possible in actual work When you need to execute a php script on the nginx command line, of course you can configure a conf for external network access.

Use

php index.php

## in the nginx command line to execute this index.php script, but how to pass it What about parameters? Then you need to use $argv and $aegc. There is no need to enable any settings. Use it directly in the script, similar to $_POST and $_GET in http value transfer.

Insert the following dishes in index.php

<?php
echo $argv[0];     echo "\n";
var_dump($argv[1]);    echo "\n";
var_dump(intval($argv[2]));  echo "\n";
echo $argv[3];     echo "\n";
echo $argc;
Copy after login

Then use

php index.php 1 10 100
Copy after login
in the nginx command line

Display

index.php      //$argv[0]显示结果 经测试此处显示的是此脚本相对于执行位置的相对路径(就是你在哪里输入的php index.php,这里显示的就是 index.php 相对于你当前目录的位置)
string(1) "1"    //$argv[1]显示第一个参数会转为字符串
int(10)        //$argv[2]显示第二个参数
100          //$argv[3]显示第二个参数
4           //$argv参数的个数 相对路径+你传的参数
Copy after login

In order to facilitate memory, I checked this variable

$avgv is the argument vector, $avgc is the argument count

Details:

http://php.net/manual/zh/reserved.variables.argv.php#93532

Summary

The above is the method introduced by the editor to execute $argv and $argc in the php script from the command line. I hope it will be helpful to you. If you have any If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank you all for your support of the php Chinese website!

Articles you may be interested in:

thinkphp5 public methods for uploading images and generating thumbnails

##Detailed explanation of the asynchronous notification and verification order processing method of calling the SDK after payment in the WeChat applet


PHP implementation of using Echarts to generate data statistical reports


The above is the detailed content of Command line execution $argv and $argc configuration method in php script_php example. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!