command line scripting development for PHP

Source: Internet
Author: User
Tags command line ini php file php code variable what php zend


What PHP can do



PHP Official document Don't facePHP can do anything it, this and the industry widely circulated to kill other programmers do not life isPHP is the best language really remote call corresponding.



PHP is mainly used in the following three areas



(1) server-side scripting



This is the main area where PHP parsers (CGI or server modules) are used with Web servers (such as Apache, Nginx).



(2) Command line script



In this way, only the PHP parser is required to execute. LenovoPythonwill understand.



(3) Desktop applications



With some extensionsPHP-GTK, you can use PHP to write desktop applications. But how boring it is to do it.



Command-line development


The following actions are performed under a Mac


Enter thephpdirectory, orphpplace the directory in the environment variable. (Mac ignores this step)



View the PHP engine



php -v

# output
PHP 5.5.27 (cli) (built: Jul 23 2015 00:21:59) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies


View Use 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


Can pass parameters



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


The parameters passed to the script can be obtained in the global variable $ argv. The global variable $ argc stores the number of member variables in the $ argv array (instead of the number of parameters passed to the script program).





001.php






Execute 001.php




php 001.php 'hello world' 2015


output



php -r 'echo Hello World
;'

#output Hello World


You can also run PHP code directly



php -r 'echo Hello World;' #Hello World

Related Article

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.