PHP variables

Today we will learn about PHP variables.

One can use PHP variables to store informations there are some rules for PHP variables such as

  • PHP variable starts with the $ sign, and followed by name of the variable.

           for example: $text

  • PHP variable name much begin with a letter or the underscore character.
  • PHP variable name can only contain alphabetic, numeric characters and underscore.
  • Variable name should not contain spaces.
  • Variable names are case sensitive.
            for example: $text and $TEXT are two different variables.
Here is simple programme for sum of two numbers using variable.
<!DOCTYPE html>




PHP has 4 different variable scopes such as

  • local
  • global
  • static
  • parameter

Local variables are declared within a PHP function and can only access within that funcion.

Global variable is declared outside of any function and It can be accessed from any part of script.
Static variable are used when you do not want to delete local variable by using static keyword before the first declaration of the variable.
Parameter is a local variable whose value is passed to the function by the calling code.

Browser detection using PHP

Today I will explain how to check what browser visitors are using with the help of user agent strings our default browser sends as a part of the HTTP request. The variable we can use to check browser is


$_SERVER is a reserved super global PHP variable that contains all the web server informations.

Lets see the example and its output result.





Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)

Create your first PHP-enabled page


Today I will explain how you can create your first php enabled page. A PHP script starts with
  <?php and ends with ?>

 First of all open any text editor(notepad++)

create a file name index.php and put it in your web server’s root OR /www OR puclic_html directory with the following content.


 echo ‘Hello World’;


Use your default browser to see output of this code with your web server’s url ending with the /index.php
If you are using localhost then try http://localhost/index.php or

If everything is fine you will see result like

Hello World

Thank you.

Things you should know about PHP

Before you start to work with PHP you should have some basic understanding about how it works, what are the requirements and what it can do? Why you should use PHP? etc.

PHP is widely used programming language to create dynamic websites
PHP scripts executed on the server side. As PHP is open source you can freely download and use. PHP files can contain text, HTML, Advance Java code. Once PHP is executed you can see result as plain HTML  in the browser. All PHP files have a default extension of .php
PHP can run of platforms like Windows, Linux, Unix, Mac. It is also compatible with almost all servers that are available today.

To develop websites using PHP you can

  • Find a web host with PHP and MySQL support (e.g
  • Install a web server on your own PC, and then install PHP and MySQL 

i.e THe Uniform server, xxamp, wamp, etc.

Official resource page for php is

Introduction to PHP

PHP is a server side language , and is a powerful tool for making dynamic Websites.
PHP stands for  Hypertext Preprocessor

It is a widely-used because it is free (open source) and efficient alternative to competitors such as Microsoft’s ASP. Also PHP can be embedded into HTML.

Here is simple example to print welcome to world of php.

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”

echo “Welcome to world of php.”;