PHP development basic tutorial: learning syntax
1. PHP syntax
The PHP script is executed on the server, and then the pure HTML result is sent back to the browser.
2. Basic PHP syntax
PHP scripts can be placed anywhere in the document.
PHP script starts with :
//This is the PHP code
? >
The default file extension for PHP files is ".php".
PHP files usually contain HTML tags and some PHP script code.
Below, we provide an example of a simple PHP file that outputs the text "Hello World!" to the browser:
php.cn 我的第一个PHP页面
Every line of code in PHP must be preceded by a semicolon Finish. A semicolon is a delimiter used to separate sets of instructions.
Through PHP, there are two basic instructions for outputting text in the browser: echo and print. These two will be explained in the following courses
3. Comments in PHP
The code in PHP will not be executed, it is a reference to the current Explanation of program code segments, comments have many functions:
1. Comment the key code segments in the program to improve code readability
2. Make it easier for new code takeovers Programmers understand
3. It is convenient to recall the code quickly after not touching the code for a long time
4. Generate documents
5. Comments can be used for troubleshooting. If you are not sure which part of the code is wrong, you can comment a large section to determine the error range
PHP supports three types of comments:
php.cn
4. PHP pair size Write Sensitivity
#In PHP, all user-defined functions, classes and keywords (such as if, else, echo, etc.) are not case-sensitive.
In the following example, all three echo statements are legal (equivalent):
php.cn
But in PHP , all variables are case-sensitive.
In the following example, only the first statement will display the value of the $name variable (this is because $name, $NAME, and $naME are considered three different variables ):
php.cn
Learning experience:
Pay attention to the semicolon after each line of code. In many cases, such an error will be reported
It should be that you forgot to add semicolons in the upper and lower lines of this line.
Comments are an important part of a program, please don’t forget it