Tuesday, 15 July 2014

Mixing PHP and HTML code

The concept of mixing  PHP and HTML means to combine both codes together without loosing their separate identity. Before getting started let's take a look at the following points.
  1. PHP is Server Side Code because it is executed or resolved on the server side, not in you browser.
  2. HTML is Client Side Code because it is executed in your browser.
Now the most important question is that how to keep separate identity of PHP code with HTML, the simple answer is, the PHP code always enclosed between two tags called Starting-tag and Ending-tag.
Any code written between these two tags are considered as PHP code, so don't forget to add these two tags when you start PHP code in HTML section. For further explanation let's take a look in the following example.
Please write the following code in your text editor and save the file as example.php or what ever you like the name but extension should be php.

<html>
<head>
<title>  Mixing PHP and HTML </title>
</head>
<body>


Hey! this is html code. <br>
 

<?php
echo "Yeh! but this is php code.";
?>


</body>
</html>


In above example
<?php and ?> are php starting and ending tags
echo is output command
Semicolon ";" at the end of echo command is called command terminator, without this terminator php unable to make decision where the current command is terminated and the new is started.

Sunday, 13 July 2014

Global Variable

A global variable is one that can be accessed from anywhere in the programming.

Each time when you declare a global variable you must keep it separate identity from the local variable because if you declared a variable as global and at the same time declared a variable with the same name as local one you simply create a logical error, so try to keep proper identification between global and local variables.

Scope of Global Variable




Sunday, 6 July 2014

PHP Variables

In general term

" A variable is a character or symbol that represents a certain value."

Suppose

A = 5
B = 2

Here
A and B are two variables
Variable A holds value 5
Variable B holds value 2

Types of PHP Variables

 Most common types of variables are given below.
  1. Local variables
  2. Global variables
  3. Static variables
  4. Function parameters