Learn PHP from a simple program
The online tutorial for the PHP site has been great. This section of this article will let you familiarize yourself with PHP . I could not have done without any omission, and my purpose was only to allow you to quickly start your PHP programming.
3.1 first condition
You first have to have a working Web server that supports PHP . I assume that all PHP files on your server have a . php3extension.
3.2 PHP the installation
For PHP installation configuration, you can check the page Pottery bar on the "PHP installation All-in" feature article.
3.3 Grammar
Syntactically, thePHP language is similar to the C language. It can be said thatPHP is a reference to C language grammatical features, improved by the C language. We can mix php code and HTML code, not only to embed the php script in the HTML file, we can even put the HTML Tags are also embedded in the PHP script. Here are a few ways you can do it. You can choose one of the most suitable and stick to this method!
Detach from HTML
Here are the methods you can use:
<? PHP ...? >
<% ...%>
Note: When you use " " to embed PHP code in an HTML file, it may conflict with XML , and the ability to use this form of reduction also depends on the php The setting itself. To accommodate XML and other editors, you can add "php" to the beginning of the question mark to adapt the PHP code to the XML parser. such as:? Lt ? PHP . . . ? >". You can also use script tags as you would write other scripting languages, suchas "".
Statement
As with Perl and C , separate the statements in PHP with ";". Flags that are separated from HTML also represent the end of the statement.
Comments
PHP support for C, c+ + and Unix -style annotation methods:
/ * c,c++ style multi-line Comment */
C + + style line Comment
# Unix Style single line comment
Echo and print
The simplest interaction between PHP and HTML is achieved through print and echo statements, and in practical use, the functions of both print and echo Almost exactly the same. It can be said that there is a place to use, and the other can be used. However, there is also a very important difference between the two: in the echo function, you can output multiple strings at the same time, and in the print function you can only output one string at a time. At the same time, theecho function does not require parentheses, so the echo function is more like a statement than a function. Let's take a look at the following example:
$a = "Hello";
$b = "World";
echo "a", "B";
Print "a", "B";
?>
With the browser watching the running of this code, you will see this running result:
Aba
Parse error:parse Error in d:adminmyphphometest.php3 on line 5
This means that the code is not completely explained, where the error occurs on line fifth of the code: "print"a "," B";".
3.4 a A simple example
With the knowledge that we've learned, you can write a simple program output that's probably the most famous word in the world of programs.
<br><?<br><span class=grame>echo</span> "Hello world!"; <BR>?><BR>
First PHP page
Single line C + + style Comment
/*
Printing the message
*/
echo "Hello world!";
# Unix Style single line comment
?>