PHP Command Line Script Development

Source: Internet
Author: User

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]
  
   
[--] [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.$argvGlobal Variables$argcExist$argvNumber 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

 

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.