PHP syntax (1-4...LOGIN

PHP syntax (1-4)

PHP Syntax

PHP scripts are executed on the server and the plain HTML results are sent back to the browser.

Basic PHP syntax

We use <?php and ?> to mark PHP code snippets. They are used to mark where PHP code begins and ends. In this way we can insert various PHP codes into HTML. To achieve dynamic web page output, this is mixing. Text within the

tag is treated as PHP code. Text outside the tag is treated as normal HTML.

PHP scripts can be placed anywhere in the document.

PHP scripts start with <?php and end with ?> :

<?php
 // PHP 代码
 ?>

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 can output the text "Hello World!" to the browser:

Example

<!DOCTYPE html> 
 <html> 
 <body> 
 
 <h1>My first PHP page</h1> 
 
 <?php 
 echo "Hello World!"; 
 ?> 
 
 </body> 
 </html>

Everything in PHP Lines of code must end with a semicolon. 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.

Comments in PHP

Examples

<!DOCTYPE html>
 <html>
 <body>
 
 <?php
 // 这是 PHP 单行注释
 /*
 这是 
 PHP 多行
 注释
 */
 ?>
 </body>
 </html>

Everyone should have learned html comments when learning html< !-- -->.

The so-called comments are comments made in the code to make it easier for people to read the code. Comments can be used to explain the purpose of the script, who wrote it, and why it was written that way. The PHP interpreter ignores all comments.

PHP has three comment methods

•       /**/Used to comment large sections of multi-line text, generally used to comment functions, classes, or complex logic (C language style)

•               // Used to comment a single line of text, generally just used to simply comment a certain line of code (C++ style)

•           # The effect is the same // (SHELL script style)


                                                                                                                      A rough schematic diagram of the interpreter, easy to understand.

Next Section

<!DOCTYPE html> <html> <body> <h1>My first PHP page</h1> <?php echo "Hello World!"; ?> </body> </html>
submitReset Code
ChapterCourseware