PHP Syntax : First PHP Script



After installing PHP on your system/server we need to write our first php program which can be executed on the server.Writing PHP script is very easy because you already know C Programming language. Many syntax in PHP are like c language. We are writing our first PHP script to print “Hello World” in the browser window.

First PHP Script :

<?php
echo "Hello World";
?>

Explanation of First PHP Script :

  1. PHP Script is simply written in notepad / notepad++.
  2. PHP Script starts with <?php and ends with ?>
  3. PHP Script can be written/placed anywhere in the document.
  4. PHP Script can be embedded in HTML document.

Shorthand Property :

We can also write PHP Script between <? and ?>.

<?
echo "Hello World";
?>

but still it is not the proper way to write/include PHP code. For maximum compatibility we cannot write above mentioned syntax.

About PHP File :

  1. Whenever we write any PHP file then we must save it using .php extension.
  2. PHP file normally contains dynamic PHP Script embedded and HTML tags.
  3. Each statement in PHP is terminated by semicolon. Semicolon is used to distinguish two code statements of PHP.
  4. In PHP we have two basic statements to print text on the webpage i.e echo and print.