PHP command-line command basics

Source: Internet
Author: User
Tags php form
This article mainly introduces the command-line command of PHP basic knowledge, interested in a friend's reference, I hope to be helpful to everyone.

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

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

Usage php [-Q] [-h] [-S] [-v] [-i] [-f] | {[args ...]} -Q Quiet mode. Do not output HTTP headers.
-S converts PHP program files into color-coded HTML (such as reserved words in green, functions and variables in blue, notes in yellow and strings red, etc.).

-F reads in and interprets the specified file.

-C read into the php.ini file in

-A interactive run

-D Foo[=bar] Define input in ini value of foo is bar

-E output additional information for debugging and performance analysis

-Z into the 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 the-S to HTML your PHP program. Is this very worry?

3. Use PHP's ODBC functionality to manipulate the database in shell commands.


Several common commands
1. View PHP version, configuration

You can view the current version of PHP by entering Php–v on 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 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.

Php--ini-in-shell


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.

<?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 results appear as follows:

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

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

-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

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

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

Summary : The above is the entire content of this article, I hope to be able to help you learn.

Related recommendations:

PHP sftp Implementation upload download function detailed analysis

PHP form file iframe Asynchronous upload instance analysis

PHP policy pattern Definition and usage (detailed)

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.