Before we proceed coding our PHP script, we need to understand first what is the syntax of coding a PHP script. A syntax is a rules that should be followed in order to write a proper structured code.
If you have a background in programming other programming langauges such as Java, C and Perl, you don’t have to worry more about the sysntax, because their syntax is almost similar to PHP and only the difference is that the PHP code contain a Tag like as the given syntax below.
- //some statements here
- //take note that PHP shorthand require a support to be enabled on your local server.
In my experience, I strongly suggest that you must use a standard PHP syntax that includes
<?php over shorthand code. This is to make sure that your scripts will run on other servers with different settings.
Here is the example PHP page with simple HTML
<html> <head> <title>PHP Syntax</title> </head> <body> <?php echo "PHP Programming is fun!"; ?> </body> </html>
Before running this page in your browser, you need to save this file with .php extension(sample.php). As you observe in our code above, we included their a PHP command“echo” which we are going to discuss this in the later part of our tutorial. And just Java or C program, we need to add semicolon at the end of our statement to signifies the end of the PHP statement.
PHP Programming is fun!