(a) basic knowledge of PHP and some points of attention

Source: Internet
Author: User

Note: Any program, including PHP, is carried out in memory at run time and the PHP code needs to be read into memory to execute.

"How PHP Works"

1. Call through the server (for example, Apache).

2. Call through the command line (no server involvement is required because there is no access to port 80).


"PHP Start and Terminator"

<?php?>

The PHP statement ends with a semicolon, but?> can replace the semicolon from its nearest sentence, because there is often a mixture of HTML and PHP written, omitting semicolons, for example:

<input type= "text" name= "username" value = "<?php echo $user?>"/>

Such a code, displays a user name input box, and the input box's initial value is the value of the variable $user.


"Comments for PHP"

PHP is similar to the C language, using//and # can comment on a single line, using/* */Can comment on multiple lines.

PHP's popular annotation standard: Phpdocumentor style annotations.

    /**     *  sum function     *     *  @param $p 1 int summand     *  @param $p 2 int addend     *     *  @return int two number of sum     *    /function func1 ($p 1, $p 2) {        return $p 1 + $p 2;    }

Note: comments affect only the PHP code, without affecting the HTML code (including plain text).

"PHP code in HTML comments"

Multi-line annotations Adopt <!----; If you nest PHP code in it, the PHP code actually executes, but the generated HTML is commented out, so it won't be displayed.

Tip: Be sure to note this when using annotations, and don't comment on PHP code like this.


"Variables for PHP"

I. Overview

1. $name = ' a '; The variable name refers to the value A. A variable contains the namespace, the value space, the reference space three parts.

A reference refers to the relationship between a variable name and a variable value.

Tip:$ is not part of the variable name, it is used only to declare a variable, and the variable and function can have the same name, and use $ to represent the variable names, not $ for the function name.

The variable name for 2.php is case-sensitive.

3. Use the Var_dump (< variables >) function to output the type and value of the variable.

4. Use the unset (< variables >) function to delete a variable and delete the variable simply by deleting the reference and the variable name without deleting the value space . PHP has its own garbage collection mechanism that automatically frees the value space that is not referenced.

Second, basic grammar

Value Pass: $a = $b; Value passing is a copy of the value space.

Reference delivery: $a = & $b; Reference passing is a copy of the reference space, and modifying the value of a also modifies B.


"Get and post"

1.GET: Sends data to the server via the requested URL.

Syntax: script name? p1=xx&p2=xx&p3=xx

PHP Gets the GET data: through the _get array.


2.POST: Generally used for form submission.

PHP gets post data: by _post array.

Implemented by sending data bodies to the server.

"Get and post submissions for simple forms"

Front:

<meta charset= "UTF-8" >    <form action= "2.php" method= "get" >        <input type= "text" name= "username" />        <input type= "text" name= "age"/> <button type=        "Submit" > Submit </button>    <br> <br>    <form action= "2.php" method= "POST" >    <input type= "text" name= "username"/>    < Input type= "text" name= "age"/>    <button type= "Submit" > Submit </button></form>

Back end:

<?php    echo "Get:";    Var_dump ($_get);    echo "<br>post:";    Var_dump ($_post);? >

TIP: Whether it is a post or get method, the data will exist in the _request variable, if get and post appear simultaneously, then _request generally save the value of _post (according to the configuration of PHP can be modified _request save which one, With PHP.ini's request_order= "GP", GP means get is in front of the post, so the post data can rewrite the Get data).

(a) basic knowledge of PHP and some points of attention

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.