PHP Command Line Script Development
What can PHP do?
The official PHP documentation is shameless.PHP can do anything
, Which is widely used in the industry and is not worth the candle for other programmers.PHP is the best language
It's actually a remote call.
PHP is mainly used in the following three fields:
(1) server scripts
This is the main field. PHP parser (CGI or server module) and web servers (such as Apache and Nginx) are used together.
(2) command line script
In this way, you only need the PHP parser for execution. Think about itPython
You will understand.
(3) desktop applications
Through some extension libraries suchPHP-GTK
You can use PHP to write desktop applications. But it's boring to do this.
Command Line Development
The following operations are performed on Mac:
Enterphp
Directory, orphp
Directory to the environment variable. (Mac ignores this step)
View PHP Engine
Php-v # output PHP 5.5.27 (cli) (built: Jul 23 2015 00:21:59) Copyright (c) 1997-2015 The PHP GroupZend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
View help
Php-h # output Usage: php [options] [-f]
[--] [Args...] php [options]-r
[--] [args...] php [options] [-B ] -R [-E ] [--] [args...] php [options] [-B ] -F [-E ] [--] [args...] php [options] -S : [-t docroot] php [options] -- [args...] php [options] -a -a Run as interactive shell -c | Look for php.ini file in this directory -n No php.ini file will be used -d foo[=bar] Define INI entry foo with value 'bar' -e Generate extended information for debugger/profiler -f Parse and execute . -h This help -i PHP information -l Syntax check only (lint) -m Show compiled in modules -r Run PHP without using script tags -B Run PHP before processing input lines -R Run PHP for every input line -F Parse and execute for every input line -E Run PHP after processing all input lines -H Hide any passed arguments from external tools. -S : Run with built-in web server. -t Specify document root for built-in web server. -s Output HTML syntax highlighted source. -v Version number -w Output source with stripped comments and whitespace. -z Load Zend extension . args... Arguments passed to script. Use -- args when first argument starts with - or script is read from stdin --ini Show configuration file names --rf Show information about function . --rc Show information about class . --re Show information about extension . --rz Show information about Zend extension . --ri Show configuration for extension .
Execute a PHP File
php [-f] xxx.php
Parameters can be passed
php [-f] xxx.php 'hello' 'world' 2015
The parameters passed to the script can be found in global variables.$argv
Global Variables$argc
Exist$argv
Number of member variables in the array (instead of the number of parameters transferred to the script program)
001.php
Execute 001.php
php 001.php 'hello world' 2015
Output
int(3)array(3) { [0]=> string(7) 001.php [1]=> string(11) hello world [2]=> string(4) 2015}
You can also run the PHP Code directly.
Php-r 'echo Hello World; '# output Hello World