PHP code written in the format

Source: Internet
Author: User

1. Code tags

PHP program can use <?php ...? > or <? ..... ? > To define PHP code, embedded in the HTML page of the pure variable is, you can use <?= $variablename?> such form

2. Indent

PHP program indentation should be in accordance with the standard keyboard 1 "tab" key, that is, 4 spaces, a program should not appear in the two kinds of indentation rules

3. Length

A) The valid code length for a single function should be within 100 lines, excluding comment lines.

b). The valid code length for a single class should be within 1500 lines, excluding comment lines.

4. Line width

The line width for each line of PHP code is set to 80 characters.

5. Interval

A) the. operator should be empty one character at a time.

b). Note Line intervals should be used between the corresponding independent function modules, and the corresponding content should be indicated.

c). A blank line should be added between the top and bottom of the program body, and no multiple blank lines should be used.

6. Align

a). Close lines of code should be aligned, such as type-decorated name parameters, etc.

b). The alignment operator should be assigned a continuous assignment.

c). If you have too many method parameters, wrap and align after the comma of each parameter

d). When the condition in the control or loop is greater than the width of the line, the line should be wrapped before the operator, aligning and annotating the appropriate condition.

e). Variables should be defined by adding space-aligned operators, and variables of the same type should be put together.

7. Brackets

A) in the use of parentheses ("()"), "(" and the key words of the function are close together, in addition to the use of the space will be "(" separate from the preceding content;

b). The statement in the curly braces ("{}") should be a single line, where: "{" Should immediately follow the statement; "}" should be aligned with the first character of the program body, and the corresponding matching module should be indicated;

c). The longer method and the "}" of the class interface should be used after the//end ... End of the logo. For example, The Terminator "}" method of the class is Terminator:} function block ends:} Loop body End:}

<? PHP//

Code tags

3.1

//

Indent in

3.2-----------------------------------------

------for ($i = 0; $i < $length; $i + +) {

if ($i

>0) {

$n = $i;

}

}

//

Variable alignment

3.6-----------------------------------------------

$count

= 100;

$length

= 0;

$user _name= null;

$porduct

= Array (); //

Declaring an array

//

Alignment of parameters

3.6----------------------------------------

------getconnection ($url,

$user _name,

$password) {

...

}//getconnection

() End

//

Line Wrap Alignment

3.6----------------------------------------------

$sql = "SELECT *".

"From tproduct WHERE prod_id =".

$pr

Od_

Id

//

Conditional justification

---------------------------------------

-------if (Condition1

//

When condition one

&& Condition2

//

and condition Two

|| Condition3) {//

or condition three

...

}

//

Space on both sides of operator

----------------------------------------

$result = (($a + 1) *3/2 + $num). ' Test ';

$condition? Func1 ($var): Func2 ($var);

?>

PHP code written in the format

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.