Php command line usage. This article mainly introduces the usage of php command lines. For more information, see php as a very popular web server scripting language. Php command line usage
This article mainly introduces the usage of php command lines. For more information, see
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 how to use php in the command line.
1. View php version and configuration
Enter php-v in the command line to view the current php version.
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.
The code is as follows:
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:
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.
The code is as follows:
-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.
The code is as follows:
-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.
The code is as follows:
-Bash-3.2 $ php-s hello. php
echo
'ddd'
;
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.
The code is as follows:
-bash-3.2$ php --rf strip_tags
Function [ function strip_tags ] {
- Parameters [2] {
Parameter #0 [ $str ]
Parameter #1 [ $allowable_tags ]
}
}
If you want to view the class using-rc; view the extension using-re.
The usage of Php command line is now over. I hope you will like it.
This article describes the usage of php command lines. For more information, see Php is a very popular web server scripting language. Actually...