"PHP" PHP basic syntax

Source: Internet
Author: User
Tags decimal to binary php language

First, what is PHP?

A) Definition: PHP is a hypertext preprocessor

b) Hypertext: The content of our 8-day study is in fact hypertext content

c) Pre-processor: the equivalent of milk in the factory processing process, although we are not visible, but we can drink the final processed milk; PHP is the same, the web needs a server side (factory) for a series of pre-processing, preprocessing, the final page is what we see the page.

Second, why should I use PHP?

A) Birth: 1995 A person named Lodorf, just to maintain their own website in C language to write the PHP language to maintain, manage and optimize their own web pages.

b) Features: Convenient, fast, open source, free

Third, your first PHP file:

A) file naming: Letters, numbers, underscores, cannot include spaces in the middle, do not use Chinese or other special symbols

b) suffix name:. php This is the PHP file format

c) When we visit a php file, we do not see any PHP code because the pre-processing of PHP has been performed on the server.

D) Note:

1. php file can be nested HTML code and PHP code

2. html files can only put HTML code and not put PHP code

Iv. language tags for php:

A) four different styles

I. <?php code content?> Standard Style

II. <script language= "PHP" > Code content </script> Long style

III. <? Code content?> Short style Note: The Short_open_tag option needs to be turned on again php.ini

Iv. <% Code Content%> ASP Style Note: The Asp_tag option needs to be turned on in php.ini

Five, the comment symbol in PHP

A)//single-line comment

b)/* Multiline Comment */

c) # script Comment

d) Features: the content of the note is not displayed in the Web page, the function of the comment is to debug the code or to interpret a piece of code

Six, PHP blank, newline, carriage return content

A) is intended to give us a clearer understanding of the contents of the code in PHP without any effect on the results of the execution!

b) Indentation, carriage return, line feed to follow the PSR Standard PSR7 standard

Vii. frequently used gadgets in PHP

A) Echo: output a piece of content in a string format

b) var_dump (): Print a piece of content (content, length, type)

Cases:

$sex = False;var_dump ($sex); Echo $sex;              Output: D:\wamp\www.lamp183\lesson09_php01\5.php:5:boolean false

Viii. Variables in PHP:

A) variables can be understood as a water Cup: A water cup is a container, it can be stored in different substances, you can drain water, tea, Sprite, the United States, peanuts, melon seeds, peeing.

b) Variable: is a variable amount

c) Definition:

1. $name = "Hai Hai";

1. $sex = "female";

2. $age = 18;

b) naming rules for identifiers:

1. You can use letters, numbers, underscores, cannot start with numbers, are strictly case-sensitive, and cannot use keywords!

2. It is best to have an associated naming method between the variable name and the content!

3. Hump Naming method

Cases:

$bgColor = "Red"; echo "BgColor";

Ix. data types that can be stored in variables

A) We have learned the variables and know how the cups are defined and used, so what can be stored in the cup.

b) Data type:

I. Four types of scalar

1. Boolean Type (Boolean)

2. Integral type (integer)

3. Float type (float)

4. String type

Ii. Two types of composite

1. Arrays (Array)

2. Object Type (objects)

III. two special types

1. Resource type (Resource)

2. Null empty type (NULL, NULL, NULL)

Ten, Boolean type data

A) Boolean data represents the opposite, right and wrong, true or false, true we usually use True to express, false we usually use false to denote

b) If you are using Echo to output a Boolean data, you will actually return a "1" and the dummy will return an empty string "";

Xi. Integer data:

A) In fact, the integer data is an integer 10 20 100 1000000

b) Range: 2147483648 ~ +2147483647

c) Classification of the binary

I. Binary: 0b

II. Eight binary: 0

III. Decimal: Not added

Iv. 16 binary: 0x

d) Conversion of the binary:

I. Binary Turn decimal:

1.10100 to decimal 20

2.11100100101 to decimal 1829

II. Decimal to binary binary:

1.128 into binary 10000000

2.5398 into binary 1010100010110

12. Floating-point data:

A) The most common is the number with a decimal point 3.14 128.256 2147483648

b) Note: Never compare two floating-point data!

I. 0.1 + 0.7 is not equal to 0.8

Cases:

$num 1=0.1, $num 2=0.7, $num 3= $num 1+ $num 2;var_dump ($num 3==0.8);    Boolean false

13. String Type:

A) A string is a text content in PHP, usually using single or double quotation marks, which is the contents of the string

b) You can use single quotation marks to define a string, or you can use double quotation marks to define

c) Single quotes do not support parsing variables

d) Double quotes can parse variables

I. Although double quotation marks can parse a variable, we recommend that you enclose the variable in a string using curly braces.

e) cannot insert single quotation marks in single quotation marks

f) Double quotation marks cannot be inserted in double quotation marks

g) Single quotation marks can be double quotes, double quotation marks can be inserted in single quotation marks, they can be interpolated, but not self-insertion

h) If you have to be self-willed, you have to plug in, you can only use the escape character backslash "\"

i) single quotation marks only support escaping the single quotation mark itself and the backslash "\"

j) Double quotes support escaping all escape symbols

k) The definition string can also be defined using the delimiter: <<<string uses string; end, note that the string at the end needs to be shelf written, otherwise invalid

I. Note: The delimiter can be inserted into single quotation marks, you can also insert double quotation marks, but also can put variables, but because he even the TAB key, space, line of the content can be recognized, so the application of relatively few

L) Conclusion: Because of single and double quotes, single quotes do not support parsing variables, double quotation marks can parse variables, so the single quotation marks are faster than double quotes!

14, NULL empty type

A) It actually indicates a state, such as a variable that does not have a value, then the state of the variable is null

b) Variables in the following three cases may be empty

I. Variable assignment is null

Ii. variables that are destroyed

Iii. non-existent variables

XV, automatic type conversion:

A) is usually automatically converted to Boolean false when the condition is judged

1. Boolean Type: False

2. Integral type: 0

3. Float type: 0.0 or 0.00

4. String type: "" or "0"

5. Array type: Arrays ()

6. Null empty type: null

7. Non-existent variables

b) is usually automatically converted to a numerical type when the mathematical operation is performed:

1. Boolean type: true = 1

2. Boolean type: false = 0

3. String type: "1234ABCD" = 1234

4. Null empty type: null = 0

c) When a string operation is performed, it is automatically converted to a string type:

1. Boolean type: true = "1"

2. Boolean: false = ""

3. Null empty type: null = ""

Vi. Coercion Type conversions:

A) Two gadgets: Settype (), GetType ()

b) Settype (): Forces the type of a variable to be set

c) Gettype (): Gets the type of a variable

D) One is to change the original variable type

I. Settype (To change the type of the variable name, "format the word");

Cases:

/* Forced type conversion */$a = 0;var_dump ($a);                 int 0settype ($a, "boolean"); Var_dump ($a);                 Boolean false

II. Boolean, Integer, float, string, array, object, NULL

e) The other is not to change the original variable type

I. Variables to receive after conversion = (word in format) variable name to change type

II. $b = "100"; $c = (integer) $b;

Cases:

Does not change the forced type conversion of the original variable type $b = "Hai hai"; var_dump ($b);            String ' length=6 ' $c = (integer) $b; var_dump ($c);            int 0

16. Small tools for judging variable types

A) is_bool (); Determine if a variable is a Boolean data

b) Is_int (); Determine if a variable is an integral type

c) is_float (); Determine if a variable is floating-point

d) is_string (); Determine if a variable is a string type

e) Is_array (); Determine if a variable is an array type

f) is_object (); Determine if a variable is an object type

g) Is_resource (); Determine if the variable is resource-based

h) is_null (); Determine if the variable is empty

17, two more special gadgets

A) Isset (); Used to detect if a variable is set

b) Empty (); Used to determine if a variable is empty

Ix. mutable variables and reference variables

A) variable variable

I. $a = "B";    $ $a = "C"; Echo $b; The result is C

Ii. Concept: The concept of variable variables is to say the value of a variable to use as their own name, to note that the value cannot be a number, it should follow the naming rules of identifiers.

b) Reference variable:

I. $a = "Hello world!"; $b = & $a;  $b = "Hello, world";  echo $a; The result of $a is "Hello, world!" ”

II. Concept: The reference address is equivalent to two variables common one address, no matter who changes the value of the variable, the other changes correspondingly, when we destroy one of the variables, another variable still exists!

18. Constants in PHP:

A) Variable: can be understood as your girlfriend, can change, but not too often

b) Constant: Can be understood as your wife, you can not change

c) Constants: In later learning, constants are used in more important places, such as a website configuration file, set the constant after, it cannot be overwritten, cannot be destroyed!

d) Definition: Define (' Constant name ', ' constant value '); Note: Constant names are usually capitalized to make it easier to distinguish

e) Use: the way to use constants is simple, write the constant name directly, note that there is no need to add any modifier symbols.

f) Note: If you output a non-existent constant name, it will be parsed as a string, but we do not recommend this way to output a string, because on the one hand it will error, on the other hand it output speed is 8 times times slower than the string

g) See if a constant has been defined: defined (constant name);

"PHP" PHP basic syntax

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.