The PHP script is executed on the server and the plain HTML results are sent back to the browser.
Basic PHP syntax
PHP scripts can be placed anywhere in the document.
PHP script starts with angle brackets, question marks, PHP<?php, and ends with ?> question marks, angle brackets:
<?php
//Here is the PHP code we want to write
?>
The default file extension for PHP files is ".php".
PHP files usually contain HTML tags and some PHP script code.
##echo display command
echo is the most commonly used command for output and display functions in PHP.
We can make it display any visible characters.Example
Below, we provide a simple PHP file example, which can output the text "Hello World!" to the browser:<!DOCTYPE html> <html> <body> <?php echo "Hello World!"; ?> </body> </html>
Note:
The code part of PHP must be written in half-width English. Many people tend to write full-width English and symbols, causing PHP code errors. Every line of code in PHP must end with a semicolon. A semicolon is a delimiter used to separate sets of instructions. The last line of PHP code can be added or not. Because many learners, especially beginners, often make a mistake: writing a line of code without adding a semicolon. Therefore, it is easy toreport errors. We usually stipulate in the company that after a line of code is written, a semicolon must be added.Comments in PHP
So-called Annotation, the Chinese explanation can be: annotation. More accurate.
So we will add comments.
Comments have many functions:
1. Mark the key points2. It’s easy to forget the quick ones after a long time Memories, easy to find3. Let others quickly understand when reading4. You can also generate documents. After the code is written, the relevant documents are finished, improving work efficiency5. The code after comments, blank lines, and carriage returns looks more beautiful 6. 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 interval7. The computer will not execute the content in the middle of the comment
We understand the benefits of comments. Next, let’s talk about PHP comments. The comments are:
Single-line comments (only comment one line)
// Double slashes represent single-line comments. Sometimes they are also represented by #, but they are rarely used. is used more //
Multi-line comments(Comment multiple lines)
Start with /* */ ends to represent a multi-line comment
Example of a single-line comment:
<?php //声明一部iphone6手机的价格变量 $iphone6_price = 6088; //显示输出手机价格 echo $iphone6_price; ?>
Note: Through the above example We know that comments are usually written above the code.
<?php /* 作者:刘奇 时间:2048.12.23 功能:这是一个假的多行注释的例子 */ /* 声明一个爱情变量 $love 是指爱情 爱情是一个变量,因为人的爱总是在发生变化 所以,爱情变量的值为250 */ $love = 250; ?>
Note: Through the above example, we found that when we need to write a lot of comments, we use multi-line comments.