On PHP command line usage _php Tutorial

Source: Internet
Author: User

On PHP command line usage


This article mainly introduces the PHP command line usage of the relevant information, the need for friends can refer to the following

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.

The code is as follows:


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.

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 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.

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 it is, using Php–s to

The code is as follows:


-bash-3.2$ php-s hello.php


Echo
' DDD '
;

style= "COLOR: #0000BB" >?>

Display effects in the browser

4. View PHP Manual

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

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 classes using –RC; View extensions using –re. The use of the

PHP command line is here to end. I hope you can enjoy

http://www.bkjia.com/phpjc /952853.html www.bkjia.com true http://www.bkjia.com/phpjc/952853.html techarticle A brief talk on PHP command line usage This article mainly introduces the PHP command line usage related data, needs the friend can refer to PHP is a very popular web service side scripting language. Actually ...

  • 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.