Home  >  Article  >  Backend Development  >  (1) Basic knowledge of PHP and some points to note_PHP tutorial

(1) Basic knowledge of PHP and some points to note_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:57:22815browse

(1) Basic knowledge of php and some points to note

Note: Any program, including PHP, is executed in memory when running, and the PHP code needs to be read into the memory to be executed.

[How php runs]

1. Called through the server (such as apache).

2. Called through the command line (no server participation is required because port 80 is not accessed).

[php starting and ending characters]

<!--?php


?-->

PHP statements end with a semicolon, but ?> can replace the semicolon in the sentence closest to it. The reason is that there is often a mixture of HTML and PHP written, and the semicolon is omitted, for example:

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

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

【php comments】

PHP’s comments are similar to C language. You can use // and # to comment a single line, and use /* */ to comment multiple lines.

Popular comment standard for PHP: PHPDocumentor style comments.

    /**
     *  求和函数
     *
     *  @param $p1 int 被加数
     *  @param $p2 int 加数
     *
     *  @return int 两数之和
     */
    function func1($p1, $p2){
        return $p1 + $p2;
    }

NOTE: Comments only affect PHP code, not HTML code (including plain text).

[php code in html comments]

Multi-line comments use . If php code is nested in it, the php code is actually executed, but the generated html is commented out, so it will not be displayed.

Tip: Be sure to pay attention to this when using comments. Do not comment on php code like this.

【php variables】

1. Overview

1.$name = 'a'; //It is said that the variable name refers to the value a. A variable consists of three parts: name space, value space, and reference space.

Reference refers to the relationship between variable name and variable value.

Tip: $ is not part of the variable name, it is just used to declare that the following is a variable; variables and functions can have the same name. When $ is used, it represents the variable name, and when $ is not used, it is used as the function name.

2.php variable names are case-sensitive.

3. Use the var_dump(68187049abec0c7dd53c11bf3b729d87) function to output the type and value of the variable.

4. Use the unset(68187049abec0c7dd53c11bf3b729d87) function to delete a variable. Deleting a variable only deletes the reference and variable name, but does not delete the value space. PHP has its own garbage collection mechanism that automatically releases unreferenced value space.

2. Basic Grammar

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

Pass by reference: $a = &$b; //Pass by reference is a copy of the reference space. Modifying the value of a will also modify b.

【GET and POST】

1.GET: Send data to the server through the requested URL.

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

php gets GET data: through _GET array.

2.POST: Generally used for form submission.

php gets POST data: through the _POST array.

Achieved by sending a data body to the server.

【Simple form GET and POST submission】

Front end:




Backend:

<!--?php
    echo "get:";
    var_dump($_GET);
    echo "<br-->post:";
    var_dump($_POST);
?>

Tip: Whether it is POST or GET, the data will be stored in the _REQUEST variable. If GET and POST appear at the same time, the value of _POST is generally stored in _REQUEST (which one _REQUEST is saved according to the configuration of php can be modified through php. ini's request_order="GP", GP means that GET comes before POST, so POST data can overwrite GET data).

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/983563.htmlTechArticle (1) Basic knowledge of php and some precautions Note: Any program, including php, is running Performed in memory, the PHP code needs to be read into the memory to be executed. 【php luck...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn