PHP Command line command usage guide _php tips

Source: Internet
Author: User
Tags odbc php and zend

When the user opens the PHP page, the server executes the PHP commands and sends the results to the user's browser, similar to the ASP and coildfusion,php that can run on Windows and multiple versions of UNIX. In addition to being able to manipulate your pages, PHP can also send HTTP headers.

You can set cookies, manage digital signatures and redirect users, and it provides excellent connectivity to other databases (and ODBC), and integrates various external libraries to do anything to parse XML in PDF documents. Do you also know that you can do something else with the power of PHP? When running as a standalone CGI, you need a PHP executable that has a number of command-line arguments, some for fun purposes, and the following are all the PHP command-line parameters, where [] means that the,<> table is optional.

Usage php [-Q] [-h] [-S] [-v] [-i] [-f] | {[args ...]} -Q Quiet mode. HTTP headers are not exported.
-S converts PHP program files into color-formatted HTML (for example, reserved words are green, functions and variables are blue, comments are yellow and strings are red, and so on).

-F reads in and interprets the specified file.

-C Read the php.ini file in

-A interactive operation

-D Foo[=bar] Defines the value of input foo in INI as bar

-e output extra information for debugging and profiling

-Z transfer into Zend extension file

-I PHP related information

-H help itself.

1. Use the Php-q file name. php to use the PHP program as a shell program,

2. Use-S to HTML your PHP program. Is this a hassle?

3. Using PHP's ODBC capabilities, you can manipulate the database in a shell command.


several common commands
1, view the version of PHP, configuration

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

 PHP 5.2.17 (CLI) (Built:feb 2 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 
 EACC Elerator 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 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.

Php--ini-in-shell


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.

 <?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 follows:

Run PHP command line Echo

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.

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

 -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

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


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

 -bash-3.2$ PHP--rf strip_tags 
  function [<internal:standard> function Strip_tags] { 
    
  -Parameters [2] { 
  Parameter #0 [<required> $s TR] 
  Parameter #1 [<optional> $allowable _tags] 
  } 
  } 

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.