2.PHP Simple Syntax Recording

Source: Internet
Author: User
Tags php language php operator

Conditions: It will be easier to understand a certain language basis; grammar knowledge, it is important, but do not merely grammar all day, this is the deviation of Chinese thinking direction, is the transition to the pursuit of conceptual understanding, the most important grammar simple look. Use the time in practical practice and code is the only way to improve the level. Recite the grammar very well without any confusion! PHP manuals are to be seen all the time. My document has the latest manual available. PhpLanguage Basics

A Learning Requirements:

1) Syntax basics for PHP

2) data type of PHP

3) How to skillfully use PHP constants, variables

4) application of various types of PHP operators

5) Application of PHP expressions

Two 1 ) Syntax Basics: Code Tags: <?php?> , notes: and HTML similar

2) data type: Common data types are integer, Boolean, float, string and null , etc.

(1) Integer type: In the system, the range is -2147483648~ 2147483647 can have eight hexadecimal, octal front plus the number 0 , Hex plus 0x .

<?php

     $str 1 =  1234 ;

     $str 2 = 01234 ;

     $str 3 = 0x1234 ;

    echo  "Php different binary : <br /> ";

    echo  " octal   :  $str 2 <br /> ";

    echo  " decimal   :  $str 1 <br /> ";

    echo  " hex   :  $str 3 <br /> ";

?

(2) Boolean: Value has true and false

Note: In logic control, not only Falser is considered false, the specific reference manual.

(3) floating point type: reference manual;

(4) Character type: single quote, double quotation mark,<<<

Note: Single quotes contain strings, and double quotes contain variables. <<< See the Manual for instructions on how to use it.

(5) NULL type: Whether the variable is controlled and detected with the is_null () function.

(6) The PHP language can be type-converted, as in C , with the operator before the type that needs to be converted.

3) Constants

(1) To declare constants use the Define () function. function format Reference manual;

(2) Predefined constants: Some of the constants built into PHP. The manual is called a magic variable.

4) variables

(1) The variable name is essentially the name of the computer's memory unit, so the data in memory can be accessed with the help of the variable name.

(2) Variable requirements I don't say much, like C, the only difference is that all the variables in PHP start with $.

(3) You need to assign a value to a variable before using it.

(4) A reference assignment is introduced here: the substance is the pointer in the C language.

<?php
$STR = "Learning php is easy";
$str 1 = & $str;
$str = "I want to tell you aloud:" $STR;
echo $str 1;
?>
(5) The scope of the variable: it is divided into global variables, local variables and static variables.
Global variables: The entire PHP file can be used, but the user-defined function is not available, if you want to use the Global keyword declaration, or through the global variable array $globals access.
Local variables: can only be used inside the function, after the function call is finished, the value of the variable is deleted, the space is freed.
Static variables: It is also used inside the function, but the difference is that after the function call is complete, the value of the variable is still there.
(6) Variable variable:
is similar to a function in mathematics. This means that if you deposit a value that is the name of another variable, you can refer to it indirectly through $$.
<?php
$STR = "name";
$name = "php,i like it";
Echo $str;
echo "<br>";
echo $ $str;
?>
(7) Pre-defined variables: self-viewing manual;

5) PHP Operator: in PHP, concatenate strings together, in other languages, such as JS, is +;

Some other operators don't say, +-*/% + +--& | ^ ~ << >> && (and) | | (OR)! Xor < <= > >=! = = = = = = =!== three mesh operator

  

Exercises:

1. Please use the PHP language to write the user input year is not a leap, leap years are judged by 4 integers can not be divisible by 100, or can be divisible by 100 can not be divisible by 400 are leap years.

2. In the development of the dynamic website of the user Registration module, where the user registration password is generally required to fill in a confirmation password, to enhance the accuracy of information input. In the user registration module, the comparison operator is applied to verify that the passwords entered two times are consistent. If the equality is entered to register the success information, the output hint is instead.

About operators, you need to know the priority.

2.PHP Simple Syntax Recording

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.