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.