Introduction to PHP command line usage Tutorials _php Tips

Source: Internet
Author: User
Tags zend

The example of this article tells the PHP command line usage, shares for everybody reference. The specific usage analysis is as follows:

PHP is a very popular Web server-side scripting language. In fact, PHP can not only play an important role in the Web server. Can be executed as at the command line.

In this article, I introduce you to the use of PHP in the command line method.

1, view the version of PHP, configuration

You can view the current version of PHP by entering Php–v at the command line.

Copy Code code as follows:
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, the Copyright (c) 2004-2010 eaccelerator, by Eaccelerator


Other options are: –m, i. The author here will not give out the son.
-m displays a valid module for the current PHP load.
-I outputs phpinfo without HTML format.

Use the –ini option to output the current number of PHP load INI configuration files, path information.

As shown in the following illustration:

2. Run the PHP program on the command line

Running PHP from the command line is very simple. But there are some caveats that need to be understood. Server variables such as $_session cannot be used on the command line, and other code runs exactly as ^_^ in the Web server.

Copy Code code as follows:
<?php
echo "Run PHP command line echo";
?>


Save the above code as hello.php. In the command line, tap Php–f hello.php. The results appear as shown in the following illustration:

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 a Web server.

Of course, we can also debug the code directly in PHP: Enter the php–r instruction, there will be a ">" symbol. This means that you have entered the shell of PHP and can write code directly and execute it.

Copy 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, the detection of PHP syntax, highlighting output

Without executing the code, we can detect the syntax errors of the PHP file under the command line.

Copy 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 output, using Php–s can

Copy Code code as follows:
-bash-3.2$ php-s hello.php
<code><span style= "color: #000000" >
<span style= "color: #0000BB" ><?php<br/></span>
<span style= "color: #007700" >echo </span>
<span style= "color: #DD0000" > ' DDD ' </span>
<span style= "color: #007700" >;<br/></span><span
style= "COLOR: #0000BB" >?><br/></span>
</span>


The results shown in the browser are as follows:

4, View the PHP manual

Starting with php5.1.2, programmers can view manuals under the PHP command line and enter PHP–RF function. Will print out the syntax introduction to the function

Copy Code code as follows:
-bash-3.2$ PHP--rf strip_tags
function [<internal:standard> function Strip_tags] {

-Parameters [2] {
Parameter #0 [<required> $str]
Parameter #1 [<optional> $allowable _tags]
}
}


If you want to see the class using –RC, view the extension using –re.

The instructions for using the PHP command line are over here. I hope this article will help you with your PHP program design.

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.