$argv and $argc configuration methods in php script

小云云
Release: 2023-03-19 06:46:01
Original
3579 people have browsed it

This article mainly introduces the methods of $argv and $argc in command line execution of php scripts. This article introduces you to it in great detail. Friends who need it can refer to it. I hope it can help you.

In actual work, you may encounter the 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

Related recommendations:


$argv and $argc in php_PHP tutorial

$argv and $argc in php

Command line variables can be used in php--$argv and $argc

The above is the detailed content of $argv and $argc configuration methods in php 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template