PHP command-line scripting development
What PHP can do
PHP Official documents do not say PHP能做任何事 , this and the industry is widely circulated to the other programmers are not life is PHP是最好的语言 really distant call corresponding.
PHP is mainly used in the following three areas
(1) server-side scripting
This is the most important area, PHP parser (CGI or server module) and Web server (such as Apache, Nginx) with the use.
(2) Command line script
In this way, only the PHP parser is required to execute. Lenovo Python will understand.
(3) Desktop applications
With some extension libraries PHP-GTK you can use PHP to write desktop applications. But it's boring to do it.
Command line development
The following actions are performed under Mac
Enter the php directory, or php place the directory in an environment variable. (Mac ignores this step)
View PHP engine
php -v# 输出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 Usage 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'll 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 PHPWithout using script tags -B Run PHP Before processing input lines-r Run PHPFor 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 str ipped comments and whitespace. -Z Load Zend extension . args ... Arguments passed to script. Use--args when first argument starts With-or script was 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 .
执行一个PHP文件
php [-f] xxx.php
可以传参数
php [-f] xxx.php 'hello' 'world' 2015
传递给脚本的参数可在全局变量$argv中获取,全局变量$argc存有$argv数组中成员变量的个数(而非传送给脚本程序的参数的个数)
001.php
执行001.php
php 001.php 'hello world' 2015
输出
int(3)array(3) { [0]=> string(7) 001.php [1]=> string(11) hello world [2]=> string(4) 2015}
也可以直接运行 PHP 代码
php -r 'echo Hello World;'#输出Hello World
http://www.bkjia.com/PHPjc/1050840.html www.bkjia.com true http://www.bkjia.com/PHPjc/1050840.html techarticle PHP Command-line script development PHP can do what PHP official documents do not say that PHP can do anything, this and the industry is widely circulated to death of other programmers of PHP is the best language can really ...