PHP syntax (2 ). Author: Hua Honglang's article "talk about PHP syntax" has talked about PHP Data types and expressions. Now let's take a look at the variables and constants of PHP. Let's take a look at this example first. File: t author: Hua Honglang
The previous article "talk about PHP syntax" has talked about PHP Data types and expressions. Now let's take a look at the variables and constants of PHP.
Let's take a look at this example first.
File: test. php
// This is a single line comment method
# This is another single line comment method
/* This is a multiline comment method.
Let's take a look at the example below */
Funtion display ($ file, $ line)
{
Global $ message;
Echo "FILE: $ file
";
Echo "LINE: $ line
";
Echo "Message: $ message
";
}
$ Message = "this is a routine. ";
Display (_ FILE _, _ LINE _);
?>
The result is as follows:
Text. php
15
This is a routine
In the preceding example, function is a custom function. The following two variables $ file and $ line are two local variables. they only play a role in the function body and do not interfere with the variation amount of the function in vitro, if $ file or $ line exists in the function body, the values of both $ file and $ line may not be the same. _ FILE _ and _ LINE _ are two constants. their limit values have been fixed. _ FILE _ is the object name, and _ LINE _ is the row number of the execution LINE. In the function body, there is also a global $ message, which is used to enable the fully qualified variable $ message to function body, this sentence can also be written as $ GLOBAL ["message"];
For information generated by GET, POST, and Cookie mechanisms, PHP automatically treats it as a PHP variable. In this way, the information processing of the submitted form is extremely easy. As follows:
File: form.html
File: deal. php
Echo "your username is: $ uname ";
?>
The above program requires the user to enter a user name, submit the form, and then return to the user name to confirm the information. It can be seen that the uname in the form has become the $ uname variable in the deal. php program. Simple. :-)
Let's take a look at the basic process control of PHP:
If... Else... Elseif
Syntax 1:
If (condition ){
Statement body
}
Syntax 2:
If (condition ){
Statement body 1
} Else {
Statement Body 2
}
Syntax 3:
If (condition 1 ){
Statement body 1
} Elseif (condition 2 ){
Statement Body 2
} Else {
Statement body 3
}
We changed the above deal. php program:
If ($ uname = "James "){
Echo "nice to see you, James. ";
} Elseif ($ uname = "Xiaohua "){
Echo "Oh, it's Xiaohua. ";
} Else {
Echo "you are $ uname, right ";
}
?>
In addition to the if statement, there is a while loop. Its syntax is as follows:
While (condition ){
Statement body
}
When the condition is true, the execution statement body.
Do... The while syntax is as follows:
Do {
Statement body
} While (condition)
Execute the statement body once. if the condition is true, execute the statement body again in a loop.
The syntax of the for loop is the same as that of C, as shown below:
For (initial condition; judgment condition; condition change) {statement}
The break jumps out of the executing loop, and the continue interrupts this loop.
Okay. here is the article. I believe you will soon be able to get started with the above basics.
-- (To be continued )--
In the previous article "talk about PHP syntax", we have discussed the data types and expressions of PHP. Now let's take a look at the variables and constants of PHP. Let's take a look at this example first. File: t...