php syntax

Basic PHP Syntax

PHP scripts can be placed anywhere in the document.

PHP scripts start with <?php and end with ?>:
<?php
// here is the PHP code
?>

The default file extension for PHP files is ".php".

PHP files usually contain HTML tags and some PHP script code.

The following example is a simple PHP file containing a PHP script that prints the text "Hello World!" on a web page using the built-in PHP function "echo":
<!DOCTYPE html>
<html>
<body>

<h1>My first PHP page</h1>

<?php
echo "Hello World!";
?>

</body>
</html>


Note: PHP statements end with a semicolon (;). The closing tag of a PHP code block also automatically indicates a semicolon (so there is no need to use a semicolon on the last line of a PHP code block).
Comments in PHP Comments in

PHP code are not read and executed as a program. Its only purpose is for code editors to read.

Comments are used to:

    Make others understand what you're doing - Comments let other programmers understand what you're doing at each step (if you work on a team)
    Remind yourself what you've done - Most programmers experience Rework the project after a year or two and then have to rethink what they did. Comments record your thoughts as you write code.
PHP supports three kinds of annotations:
Examples
<!DOCTYPE html>
<html>
<body>

<?php
// this is a single line comment

# This is also a single line comment

/*
This is a multi-line comment block
it spans
Multi-line
*/
?>

</body>
</html>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326524543&siteId=291194637