Talking about PHP command line usage, talking about PHP command line
PHP is a very popular web service-side scripting language. In fact, PHP can not only play an important role in the Web server. Can be executed at the command line.
In this article, I will introduce you to PHP in the command line of the use of the method.
1. View PHP version, configuration
You can view the current version of PHP by entering Php–v on the command line.
Other options are: –m,-I. The author here will not give out the son.
-M displays the active module for the current PHP load.
-I outputs a phpinfo without HTML format.
Use the –ini option to output the number and path information for the current PHP load INI configuration file.
2. Run the PHP program on the command line
Running PHP from the command line is easy. But there are some caveats that you need to know. Server variables such as $_session cannot be used on the command line, and other code runs exactly as ^_^ in the Web server.
Copy the Code code as follows:
<?php
echo "Run PHP command line echo";
?>
Save the above code as hello.php. In the command line, Php–f hello.php is typed. The results appear as follows:
One of the benefits of executing PHP files on the command line is that you can implement some of the scheduled tasks through scripting. Without the need to ^_^ through the Web server.
Of course, we can also debug the code directly in PHP: Enter the php–r instruction, a ">" symbol appears. This means that you have entered the shell of PHP and can write the code directly and execute it.
Copy the Code code 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 interactive mode, enter a line of code, PHP will output the results in real time.
3. Check php syntax, highlight output
Instead of executing code, we can detect PHP file syntax errors at the command line.
Copy the Code code 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 it is, using Php–s to
Copy the Code code as follows:
-bash-3.2$ php-s hello.php
<?php
echo
'ddd'
;
style="color: #0000BB">?>
在浏览器中的显示效果
4、查看php手册
从php5.1.2开始,程序员们可以在php命令行下查看手册了,输入php –rf function。会打印出该函数的语法简介
复制代码 代码如下:
-bash-3.2$ php --rf strip_tags
Function [ function strip_tags ] {
- Parameters [2] {
Parameter #0 [ $str ]
Parameter #1 [ $allowable_tags ]
}
}
如果要查看类使用 –rc;查看扩展使用 –re。
Php命令行的使用方法介绍到这里就结束了。希望大家能够喜欢
http://www.bkjia.com/PHPjc/953145.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/953145.htmlTechArticle浅谈php命令行用法,浅谈php命令行 Php是一个非常流行的web服务端脚本语言。其实,php不仅仅可以在web服务器中充当重要角色。在命令行一样...