1Basic PHP Syntax
2A PHP script can be placed anywhere in the document.
3
4A PHP script starts with <?php and ends with ?>:
5
6<?php
7// PHP code goes here
8?>
9The default file extension for PHP files is ".php".
10
11A PHP file normally contains HTML tags, and some PHP scripting code.
12
13Example
14<!DOCTYPE html>
15<html>
16<body>
17
18<h1>Php in html</h1>
19
20<?php
21echo "Hello World!";
22?>
23
24</body>
25</html>
1
2You may want to know that removing semicolon is optional sometime but need to know the condition when it can be removed and when it can't be.
3-------------------------------------------------------------------------
4// Example 1: PHP script with closing tag at the end.
5<?php
6
7// php code
8
9// you can remove semicolon
10mysqli_close( $db )
11?>
12
13// Example 2: PHP script without closing tag at the end.
14<?php
15
16// php code
17
18// you can't remove semicolon
19mysqli_close( $db )
20
21-----------------------------------------------------------------------
22
23