PHP command-line scripting development

Source: Internet
Author: User
Tags what php zend

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] <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-a Run as interactive shell-c <path>|<file> look for php.ini file in this di               Rectory-n No php.ini file would 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 Lin E-f <file> Parse and execute <file> for 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 was read from stdin--ini Show config  uration 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

Can pass parameters

php [-f] xxx.php ‘hello‘ ‘world‘ 2015

Parameters passed to the script can be obtained in global variables $argv , and global variables have the $argc $argv number of member variables in the array (not the number of parameters passed to the script)

001.php

<?phpvar_dump($argc);echo "\n";var_dump($argv);?>

Perform 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";‘#输出Hello World

Of course, PHP's command-line development not only above these content, here can see more http://php.net/manual/zh/features.commandline.php

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Command-line script development for PHP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.