PHP syntax
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, and ends with?>question marks, angle brackets:
//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
echois 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: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 to report errors. We usually stipulate in the company that after a line of code is written, a semicolon must be added.Comments in PHP
So-calledAnnotation, the Chinese explanation can be: annotation. More accurate.
So we will addcomments.
Comments have many functions:
1. Mark the key points 2. It’s easy to forget the quick ones after a long time Memories, easy to find 3. Let others quickly understand when reading 4. You can also generate documents. After the code is written, the relevant documents are finished, improving work efficiency 5. 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 interval 7. The computer will not execute the content in the middle of the commentWe 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:
Note: Through the above example We know that comments are usually written above the code.
Note: Through the above example, we found that when we need to write a lot of comments, we use multi-line comments.