Comments In PHP

Comments in php code are lines that are not read or executed as part of the program. Its purpose is to indicate some guiding text to  the person editing the code.

Comments are useful for:

  • To let others understand what you are doing, comments help other programmers understand what you were doing in each step.
  • To remind yourself, what you were working on. Most programmers have experienced coming back to their own work a year or two later and have to re-figure the working of their program.

PHP suppports three ways of adding comment/s.

Single Line Comment





Multi-line Comment






PHP Case Sensitivity

In PHP, All user defined functions, Classes and keywords are not Case Sensitive.



echo "EXAMPLE";


Both statements will execute.


My First PHP Program

PHP Program must run on a PHP enabled web server.

A PHP Program can be placed anywhere in the document. A PHP script starts with <?php and ends with ?>

first php program

The default extension of PHP file is .php

Writing First PHP Program

A PHP script file normally contains HTML tags and some PHP scripting code.



<h1> My First PHP Page </h1>


echo "Hello World";




echo is built-in PHP function to output the text on a web page.

Save this file with .php extension. create a public folder, save this file in this folder. Save this folder in www folder on WAMP server.

# Start Server

# Type in Browser “http://localhost/

# Navigate to the folder where we have placed the php file.

# Open your php file in browser. it will display your newly created page.



PHP Script Basics

PHP Script Basics

PHP is a scripting language which is used for developing dynamic webpages. Php script and html code can share same file for the development. So to differentiate php code from other stuff. There are four ways to define syntax :

1.  The Most common ways is to use Canonical PHP tags to mark where is php code

   <?php /*place your php code here*/ ?>


2. Short-Open tags is the shortest option one can use, but for using this, one must :

  •        Choose the –enable-short-tags configuration option when you’re building PHP script.
  •        Set the short_open_tag setting in your php.ini file to on. This option must be disabled to parse XML with PHP because the same syntax is used for XML tags.

   <? /* Your php code here */ ?>


3. ASP style tags are just like actual Active Server Pages tags.  And can be used after some configuration in php.ini file.

   <% your php code %>


4. HTML script tags are just how we add any javascript in html. Just replace javascript with PHP and place your code within the script tags.

   <script language="PHP">...</script>


The file which contain php code should be saved with .php or any other compatible extension.