Php command line usage getting started instance tutorial, php command line instance tutorial _ PHP Tutorial

Source: Internet
Author: User
Php command line usage getting started instance tutorial, php command line instance tutorial. Php command line usage getting started instance tutorial. php command line instance tutorial this article describes the php command line usage for your reference. The specific usage analysis is as follows: Php is a non-php command line usage getting started instance tutorial, php command line instance tutorial

The example in this article describes the usage of php command lines for your reference. The usage analysis is as follows:

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.


The code is 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 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.

As shown in:



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:

<? Php
Echo "run php command line echo ";
?>



Save the above code as hello. php. Input php-f hello. php in the command line. Shows the result:



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

<?php

echo
'ddd'
;
style="color: #0000BB">?>



The display effect in the browser is as follows:



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 this article will help you with PHP programming.



PHP uses the command line to call the application online and instruct me to give you all my points.


Is there an error message? Check the security level of php. ini. is the exec function restricted?

Php command line cannot run php files


Either your PHP is not installed in the system, or your PHP file has a syntax error.
Run the php-v command first to check whether the PHP version information is displayed. if not, the PHP installation error occurs;
If no error occurs, write a xx. php file with the following content: Save and execute the php-f xx. php command to check whether the command is correctly run.


Examples in this article describe php command line usage and share it with you for your reference. The 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.