This article mainly introduces the PHP Command Line command user guide, which is the basic knowledge in PHP beginners. If you need it, refer
This article mainly introduces the PHP Command Line command user guide, which is the basic knowledge in PHP beginners. If you need it, refer
When a user opens the php page, the server executes the PHP Command and sends the execution result to the user's browser, which is similar to ASP and CoildFusion, PHP can run on WINDOWS and multiple versions of UNIX. In addition to being able to operate on your page, PHP can also send HTTP headers.
You can set cookies, manage digital signatures, and redirect users, and provide excellent connectivity to other databases (as well as ODBC ), integrate various external libraries to parse XML in PDF documents. Do you still know that you can use the powerful functions of php to do something else? When running in an independent cgi Mode, a php executable program is required. It has many command line parameters, some of which can be used for interesting purposes. Below are all the php Command Line parameters, [] indicates that the table is dispensable. <> the table is required.
Use php [-q] [-h] [-s] [-v] [-I] [-f] | {[args...]}-q quiet mode. No HTTP header is output.
-S converts php program files to HTML in color format (for example, the reserved words are green, the functions and variables are blue, the comments are yellow, and the strings are red.
-F reads and interprets the specified file.
-C reads the php. ini file in
-A Interactive Operation
-D foo [= bar] defines the input item foo in ini as bar.
-E outputs additional information for debugging and Performance Analysis
-Z: Call Zend extension file
-I php-related information
-H help itself.
1. Use php-q file name. php to use the php program as a shell program,
2. Use-s to html Your php program. Isn't that easy?
3. Use the odbc function of php to operate databases in shell commands.
Several Common commands
1. View php version and Configuration
Enter php-v in the command line to view the current php version.
PHP 5.2.17 (cli) (built: Feb 2 2011 11:19:21) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies 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.
Php -- ini-in-shell
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 echo "run php Command Line echo";?>
Save the above Code as hello. php. Input php-f hello. php In the command line. The result is as follows:
Run php Command Line echo
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 the php shell has been entered, and the code can be directly written and executed.
-Bash-3.2 $ php-R'> for ($ I = 0; $ I <2; $ I ++) {> echo "Number: {$ I} \ n ">}> 'Number: 0 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.
-Bash-3.2 $ php-l hello. php
No syntax errors detected in hello. php
Programmers often need to highlight the php code as is and use php-s.
-Bash-3.2 $ php-s hello. php
<? Php
Echo 'ddd ';
?>
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.
-bash-3.2$ php --rf strip_tags
Function [ function strip_tags ] {- Parameters [2] {Parameter #0 [ $str ]Parameter #1 [ $allowable_tags ]}}