PHP command-line Usage Primer tutorial, PHP command-line Instance Tutorial _php Tutorial

Source: Internet
Author: User

PHP command-line usage Walkthrough Tutorial, PHP command-line Instance tutorial


The example of this article describes the PHP command line usage, share to everyone for your reference. The specific usage analysis is as follows:

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.

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

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.

As shown in the following:

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 display results are 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。会打印出该函数的语法简介

The

Copy Code code is as follows:-bash-3.2$ php--rf strip_tags
Function [ function S Trip_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 this article is helpful to everyone's PHP programming


PHP using the command line to invoke the application Online guide I'll give you all my points.

 

PHP files can not be run using the PHP command line

Either you PHP is not installed in the system, or your PHP file has a syntax error.
You first use: php-v command to see if it will show the version of PHP information, if it is not PHP installed error,
If not, you write a xx.php file, the content is: !--? php echo "Hello, world!& #92; n";?--> then save, execute php-f xx.php command to see if it's working correctly.
 

http://www.bkjia.com/phpjc/901288.html Span id= "Indexurl" itemprop= "Indexurl" >www.bkjia.com true http://www.bkjia.com/phpjc/901288.html techarticle php command line usage Getting Started instance tutorial, PHP command-line Instance Tutorial This article describes the PHP command-line usage, share to everyone for your reference. The specific usage analysis is as follows: PHP is a non-...

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