Basic PHP syntax
The PHP script can be placed anywhere in the document.
The PHP script starts with <?php and ends with?>:
1 <? PHP 2 // PHP Code 3 ?>
The default file name extension for PHP files is ". php".
PHP files usually contain HTML tags and some PHP script code.
Below, we provide a simple example of a PHP file that can output the text "Hello world!" to the browser:
1 <! DOCTYPE html> 2 3 <body> 4 5 6 7 <?php 8 echo "Hello world!"; 9 ?>11
</body>
Each line of code in PHP must end with a semicolon. A semicolon is a delimiter used to differentiate the instruction set.
With PHP, there are two basic instructions for outputting text in the browser:echo and print.
Comments in PHP
1 <! DOCTYPE html> 2 3 <body> 4 5 <?php 6 //This is PHP single line comment 7 8/* 9 This is PHP multi-line note */13 ?> </body>
3. PHP Tutorial _3. PHP syntax