About PHP Syntax (2) _php tutorial

Source: Internet
Author: User
Author: China Red Wolf


The previous article, "Talking about PHP syntax", has talked about PHP data types and expressions. Now, let's look at the variables and constants of PHP.
Let's take a look at the first example.
Files: test.php
This is a single-line annotation method
#这是另一种单行注释方法
/* This is a multi-line annotation method
Let's take a look at the following example.
funtion display ($file, $line)
{
Global $message;
echo "FILE: $file
";
echo "Line: $line
";
echo "Message: $message
";
}

$message = "This is a routine. ";
Display (_file_,_line_);
?>
The results shown are:
text.php
15
This is a routine

In the example above, function is the definition of a custom function. The following two variables, $file and $line, are two local variables that work only in the function body, and do not interfere with the amount of variable Queensland unlimited outside the function body, and if there are $file or $line outside the function body, the values of two $file and two $line are not necessarily the same. _file_ and _line_ are two constants, and their Queensland unlimited values are already fixed. _file_ is the file name for this file, and _line_ is the line number where the row is executed. In the function body there is another sentence for global $message; Its function is to make the whole Queensland unlimited local variable $message can act in the function body, this sentence can also be written $global["message"];
For information generated by mechanisms such as GET, post, and cookies, PHP automatically treats it as a PHP variable. In this way, it is particularly easy to make the processing of the submitted form explicit. As follows:
Files: form.html
<title></title>




Files: deal.php
echo "Your username: $uname";
?>

The above program will require the user to enter a user name, submit the form, and then back to the user name confirmation information. It can be seen that the uname in the form has become the $UNAME variable Queensland Unlimited in the deal.php program. It's simple. :-)
Here's a look at PHP's basic flow control:
If...else ... Elseif
Syntax One:
if (condition) {
Statement body
}
Syntax Two:
if (condition) {
Statement Body One
}else{
Statement Body Two
}
Syntax Three:
if (condition 1) {
Statement Body One
}elseif (condition 2) {
Statement Body Two
}else{
Statement Body Three
}
Let's change the deal.php procedure above to read:
if ($uname = = "Xiaoming") {
echo "How nice to see you, Xiaoming." ";
}elseif ($uname = = "Xiao Hua") {
echo "Oh, it's Xiao Hua." ";
}else{
echo "You are $uname, right";
}
?>
In addition to the IF statement, there is a while loop, which has the following syntax:
while (condition) {
Statement body
}
Executes the statement body when the condition is true.
The syntax for Do...while is as follows:
do {
Statement body
}while (condition)
Executes the statement body first, and if the condition is true, the loop executes the statement body again.
The syntax for the For loop is the same as C, as follows:
for (conditional initial; judging condition; condition change) {statement}
And break jumps out of the loop that is being executed, continue to interrupt the loop.
OK, here's the article. Some of the basics above believe that you will soon be able to get started.
--(to be continued)--

http://www.bkjia.com/PHPjc/315518.html www.bkjia.com true http://www.bkjia.com/PHPjc/315518.html techarticle Author: China Red Wolf on a "Talk about PHP syntax" has been discussed in PHP data types and expressions. Now, let's look at the variables and constants of PHP. Let's take a look at the first example. File: T ...

  • 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.