PHP basic syntax is nothing it just how to start writing PHP script. Basically, it gives the basic structure of PHP. There are three methods to start writing PHP scripts.
- The basic syntax of PHP starts with <?php and ends with ?>.
- And also used short tag starts with <? and ends with ?>.
- It's also a valid syntax '< script language="php" and ends with </script>.
The PHP script could be placed anywhere in the HTML document.
PHP Basic Syntax Example
<?php echo " Generally used syntax of php "; ?> <script language="php"> echo"Html script tag type syntax"; </script> <?php echo "both are working properly"; ?>
In the above example, all three method are shown. Every type of structure has one echo statement that will print something on the screen.
The start and end code must with the same tag, for example the code cannot start with <?php and end with</script>.
The semicolon (;) signifies the end of a PHP statement. There should be a semicolon after each line.
PHP semicolon Example
<?php echo "There should be a semicolon after each line."."
"; echo "like this."."
"; echo "Use of semicolon."."
"; echo date("Y-m-d")."
In the above example there are four echo statements and at the end of each echo statement semicolon must be there.
Example of semicolon
<?php $name_of_student = "John" echo $roll_of_student; ?>
If you did not terminate any PHP statement then error message will occur as shown in above.