Php command line usage introduction, php command line usage _ PHP Tutorial

Source: Internet
Author: User
Php command line usage introduction, php command line usage. Php command line usage introduction, php command line usage Php is a very popular web server scripting language. In fact, php can not only play an important role in web servers. In the same command line as in the php command line usage introduction, php command line usage

Php is a very popular web server scripting language. In fact, php can not only play an important role in web servers. It can be executed in the same way as the command line.

In this article, I will introduce youPhp in the command lineInUsage.

1. View php version and configuration

Enter php-v in the command line to view the current php version.

Java code
  1. PHP 5.2.17 (cli) (built: Feb 2 2011 11:19:21)
  2. Copyright (c) 1997-2010 The PHP Group
  3. Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
  4. With Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies
  5. With eAccelerator v0.9.6.1, Copyright (c) 2004-2010 eAccelerator, by eAccelerator

Other options include-m and-I. I will not give a column here.

-M displays the valid modules loaded by php.

-I: No phpinfo in html format is output.

You can use the-ini option to output the quantity and path information of the ini configuration file loaded by the current php.

2. run the php program in the command line.

It is very easy to run php from the command line. However, you need to know some precautions. Server variables such as $ _ SESSION cannot be used in the command line, and other code runs exactly the same as pai_^ on the web server.

Php code
  1. Echo "run php command line echo ";
  2. ?>

Save the above code as hello. php. Input php-f hello. php in the command line. The result is as follows:

One of the advantages of executing the php file in the command line is that you can execute some scheduled tasks through scripts. Instead of using the web server pai_^.

Of course, we can also directly debug the code in php: Enter the php-r command and a ">" symbol will appear. This indicates that you have entered the php shell and can directly write and execute the code.

Java code
  1. -Bash-3.2 $ php-R'
  2. > For ($ I = 0; $ I <2; $ I ++ ){
  3. > Echo "Number: {$ I} \ n ";
  4. >}
  5. >'
  6. Number: 0
  7. Number: 1

You can also use the php-a command to open the interactive mode and enter a line of code. php will output the result in real time.

3. check php syntax and highlight output

You do not need to execute the code. we can check the php file syntax errors in the command line.

Java code
  1. -Bash-3.2 $ php-l hello. php
  2. No syntax errors detected in hello. php

Programmers often need to highlight the php code as is and use php-s.

Java code
  1. -Bash-3.2 $ php-s hello. php
  2. "color: #000000">
  3. "color: #0000BB"><?php
  4. "color: #007700">echo 
  5. "color: #DD0000">'ddd'
  6. "color: #007700">;
  7. style="color: #0000BB">?>

Display effect in the browser

4. view the php Manual

Starting from php5.1.2, programmers can view the manual under the php command line and enter the php-rf function. The syntax of the function is printed.

Java code
  1. -Bash-3.2 $ php -- rf strip_tags
  2. Function [ Function strip_tags] {
  3. -Parameters [2] {
  4. Parameter #0 [ $ Str]
  5. Parameter #1 [ $ Allowable_tags]
  6. }
  7. }

If you want to view the class using-rc; view the extension using-re.

The usage of Php command line is now over. Enjoy It!

Source: http://www.cnphp.info/php-command-line-useage-intro.html

MORE: http://www.tutorialspoint.com/unix_commands/php.htm

Php-Unix, Linux Command

NAME

Php-PHP Command Line Interface 'cli'

SYNOPSIS

Php[Options] [-F]File[[--]Args...]

Php[Options]-R Code[[--]Args...]

Php[Options] [-BCode]-R Code[-ECode] [[--]Args...]

Php[Options] [-BCode]-F File[-ECode] [[--]Args...]

Php[Options] -- [Args...]

Php[Options]-

DESCRIPTION

PHPIs a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. This is the command line interface that enables you want to do the following:

You can parse and execute files by using parameter-f followed by the name ofFileTo be executed.

Using parameter-r you can directly execute PHPCodeSimply as you wowould do inside. PhpFile when usingEval ()Function.

It is also possible to process the standard input line by line using either the parameter-R or-F. In this mode each separate input line causesCodeSpecified by-R orFileSpecified by-F to be executed. You can access the input line$ Argn. While processing the input lines$ ArgiContains the number of the actual line being processed. Further more the parameters-B and-E can be used to executeCode(See-r) before and after all input lines have been processed respectively. Notice that the input is read fromSTDINAnd therefore reading fromSTDINExplicitly changes the next input line or skips input lines.

If none of-r-f-B-R-F or-E is present but a single parameter is given then this parameter is taken as the filename to parse and execute (same as -f ). if no parameter is present then the standard input is read and executed.

OPTIONS

Tag Description

-- Interactive
-
Run PHP interactively. This lets you enter snippets of PHP code that directly get executed. When readline support is enabled you can edit the lines and also have history support.
-- BindpathAddress: port|Port
-BAddress: port|Port
Bind Path for external FASTCGI Server mode (CGI only ).
-- No-chdir
-C
Do not chdir to the script's directory (CGI only ).
-- No-header
-Q
Quiet-mode. Suppress HTTP header output (CGI only ).
-- TimingCount
-TCount
Measure execution time of script repeated count times (CGI only ).
-- Php-iniPath|File
-CPath|File
LookPhp. iniFile in the directoryPathOr use the specifiedFile
-- No-php-ini
-N
NoPhp. iniFile will be used
-- DefineFoo[=Bar]
-DFoo[=Bar]
Define INI entryFooWith valueBar
-E Generate extended information for debugger/profiler
-- FileFile
-FFile
Parse and executeFile
-- GlobalName
-GName
Make variableNameGlobal in script.
-- Help
-H
This help
-- Hide-args
-H
Hide script name (File) And parameters (Args...) From external tools. For example you may be want to use this when a php script is started as a daemon and the command line contains sensitive data such as passwords.
-- Info
-I
PHP information and configuration
-- Syntax-check
-L
Syntax check only (lint)
-- Modules
-M
Show compiled in modules
-- RunCode
-RCode
Run PHPCodeWithout using script tags' '
-- Process-beginCode
-BCode
Run PHPCodeBefore processing input lines
-- Process-codeCode
-RCode
Run PHPCodeFor every input line
-- Process-fileFile
-FFile
Parse and executeFileFor every input line
-- Process-endCode
-ECode
Run PHPCodeAfter processing all input lines
-- Syntax-highlight
-S
Output HTML syntax highlighted source
-- Version
-V
Version number
-- Stripped
-W
Output source with stripped comments and whitespace
-- Zend-extensionFile
-ZFile
Load Zend extensionFile
Args... Arguments passed to script. Use'--' ArgsWhen first argument starts'-'Or script is read from stdin
-- Rfunction Name
-- Rf NameShows information about functionName
-- Rclass Name
-- Rc NameShows information about className
-- Rextension Name
-- Re NameShows information about extensionName
-- Rextinfo Name
-- Ri NameShows configuration for extensionName
-- Ini Show configuration file names

FILES

Tag Description

Php-cli.ini The configuration file for the CLI version of PHP.
Php. ini The standard configuration file will only be used whenPhp-cli.iniCannot be found.

EXAMPLES

Tag Description

Php-r 'echo "Hello World \ n ";'
This command simply writes the text "Hello World" to standard out.
Php-r 'print _ r (gd_info ());'
This shows the configuration of your gd extension. you can use this to easily check which image formats you can use. if you have any dynamic modules you may want to use the same ini file that php uses when executed from your webserver. there are more extensions which have such a function. for dba use:Php-r 'print _ r (dba_handlers (1 ));'
Php-R 'echo strip_tags ($ argn). "\ n ";'
This PHP command strips off the HTML tags line by line and outputs the result. To see how it works you can first look at the following PHP command'Php-d html_errors = 1-I'Which uses PHP to output HTML formatted configuration information. If you then combine those two'Php... | php...'You' ll see what happens.
Php-E 'echo "Lines: $ argi \ n ";'
Using this PHP command you can count the lines being input.
Php-R' @ $ l + = count (file ($ argn); '-E' echo "Lines: $ l \ n ";'
In this example PHP expects each input line being a file. it counts all lines of the files specified by each input line and shows the summarized result. you may combine this with tools like find and change the php scriptlet.
Php-R 'echo "$ argn \ n"; fgets (STDIN );'
Since you have access to STDIN from within-B-R-F and-E you can skip certain input lines with your code. but note that in such cases $ argi only counts the lines being processed by php itself. having read this you will guess what the above program does: skipping every second input line.

TIPS

You can use a shebang line to automatically invoke php from scripts. Only the CLI version of PHP will ignore such a first line as shown below:

#! /Bin/php

// Your script

?>

SEE ALSO

Http://www.php.net/manual/

BUGS

You can view the list of known bugs or report any new bug you found:

Http://bugs.php.net

AUTHORS

The PHP Group: Thies C. Arntzen, Stig Bakken, Andi Gutmans, Rasmus Lerdorf, Sam Ruby, Sascha Schumann, Zeev Suraski, Jim Winstead, Andrei Zmievski.

Additional work for the CLI sapi was done by Edin Kadribasic, Marcus Boerger and Johannes Schlueter.

A List of active developers can be found here:

Http://www.php.net/credits.php

And last but not least PHP was developed with the help of a huge amount of contributors all around the world.

VERSION INFORMATION

This manpage describesPhp, Version 5.2.17.

COPYRIGHT

Copyright©1997-2010 The PHP Group

Php is a very popular web server scripting language. In fact, php can not only play an important role in web servers. The same as in the command line...

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.