ITSourceCode.com

We Exist to Provide 100% Free Source Code and Tutorials

Custom Search

03- PHP Syntax

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.

PHP Code:

  1. <?php
  2. //some statements here
  3. ?>

For shorthand:

  1. <?
  2. //take note that PHP shorthand require a support to be enabled on your local server.
  3. ?>

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.

Output:
PHP Programming is fun!

Facebook Comments

Check Your Domain Ranking

Leave a Reply

Your email address will not be published. Required fields are marked *

ITSourceCode.com © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!