php basics

1. PHP is a scripting language that runs on the server side and can be embedded in HTML.

2. php code markup

  In the historical development of php, various tags can be used to distinguish php scripts

  a. ASP tag: <% php code%>

  b. Short tag: <?php code?>

  c. Script tag: <script language=“php”>php code</script>

  d. Standard tags (commonly used): <?php php code?>

  Note: a and b are basically deprecated. If you want to use it, you need to open it in the configuration file

 

3. php comments

  a, single-line comment

    //: The following comment content

    #:the same with

  b. Multi-line comments

    /* Fill in the comments in the middle */

 

4, php statement separator

  A semicolon in English: ";" means the end of a sentence.

  Notice:

    a. Tag terminator in php? > Has the effect of its own statement terminator, the last line of php code can have no statement terminator

    b. In fact, many codes written in php are not embedded in HTML, but exist independently. Usually, it is not recommended to use the tag terminator?> in writing habits, and php will automatically consider all the php codes from the beginning to the end, so as to parse.

 

5. Variables

You don't need any keywords to define variables in php.

All variables in php must use "$" sign, like $var=0;

Variable deletion: delete variables using unset(variable name) unset($var)

 

Note: variable names in php must start with a "$" sign;

 

Predefined variables: variables defined in advance, variables defined by the system, store a lot of data that needs to be used (predefined variables are arrays)

$_GET: Get all the data submitted by the form in get

$_POST: The data submitted by POST will be saved here

$_REQEST: Both GET and POST submissions will be saved

$GLOBALS: All global variables in PHP

$_SERVER: server information

$_SESSION: session session data

$_COOKIE: cookie session data

$_ENV: Environment information

$_FILES: User uploaded file information

 

Passing variables:

  Value passing: $a=10;$b=$a;$b=5; result $a=10, $b=5

  Pass by reference: $c=10;$d=&$c;$c=5; The result is that both $c and $d are 5 

The address is passed by reference.

 

6. Constants

a. Use functions that define constants: define('constant name', 'constant value');

b. const constant name = value;

(constants usually do not add $)

 

Several commonly used system constants:

PHP_VERSION: PHP version number

PHP_INT_SIZE: Integer size

PHP_INT_MAX: the maximum value that an integer can represent (integers in php allow negative numbers)

 

Magic constants:

__DIR__: The absolute path of the computer where the current script is located

__FILE__: The absolute path (with file name) where the current script is located

__LINE__: the current line number

__NAMESPACE__: the current namespace

__CLASS__: the current class

__METHOD__: the current method

 

7. Data type

PHP is a weakly typed language, variables themselves have no data type

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325145753&siteId=291194637