10

Command Line Arguments in PHP

 3 years ago
source link: https://www.devdungeon.com/content/command-line-arguments-php
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Command Line Arguments in PHP

Submitted by NanoDano on Mon, 07/27/2015 - 19:31

In PHP, all command line arguments, including the script name itself are stored in a special array named $argv. The first element, zero, is the name of the script being run. For example:

<?php
echo "This script being executed is named " . $argv[0] . ".\n";

If you run

php myScript.php

The output will be

This script being executed is named test.php.

The output will be the same if you begin the file with a shebang like #!/usr/bin/php and run the script by typing

./myScript.php

All subsequent arguments will be in the $argv array.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK