PHP Command Line Script Development and 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 languageIt'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 itPythonYou will understand.
(3) desktop applications
Through some extension libraries suchPHP-GTKYou can use PHP to write desktop applications. But it's boring to do this.
Command Line Development
The following operations are performed on Mac:
EnterphpDirectory, orphpDirectory 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] <file> [--] [args...] php [options]-r <code> [--] [args...] php [options] [-B <begin_code>]-R <code> [-E <end_code>] [--] [args...] php [options] [-B <begin_code>]-F <file> [-E <end_code>] [--] [args...] php [options]-S <addr>: <port> [-t docroot] php [options] -- [args...] php [options]-a Run as interactive shell-c <path> | <file> 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 <file> Parse and execute <file >. -h This help-I PHP information-l Syntax check only (lint) -m Show compiled in modules-r <code> Run PHP <code> without using script tags <?...?> -B <begin_code> Run PHP <begin_code> before processing input lines-R <code> Run PHP <code> for every input line-F <file> Parse and execute <file> every input line-E <end_code> Run PHP <end_code> after processing all input lines-H Hide any passed arguments from external tools. -S <addr>: <port> Run with built-in web server. -t <docroot> Specify document root <docroot> for built-in web server. -s Output HTML syntax highlighted source. -v Version number-w Output source with stripped comments and whitespace. -z <file> Load Zend extension <file>. args... arguments passed to script. use -- args when first argument starts with-or script is read from stdin -- ini Show configuration file names -- rf <name> Show information about function <name>. -- rc <name> Show information about class <name>. -- re <name> Show information about extension <name>. -- rz <name> Show information about Zend extension <name>. -- ri <name> Show configuration for extension <name>.
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.$argvGlobal Variables$argcExist$argvNumber of member variables in the array (instead of the number of parameters transferred to the script program)
001. php
<?phpvar_dump($argc);echo "\n";var_dump($argv);?>
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 \ n"; '# output Hello World
Of course, PHP Command Line development not only the above content, here you can view more http://php.net/manual/zh/features.commandline.php
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.