Before checking the code Install EASYPHP 1.8.After installation go to the location where you have installed a EASYPHP 1.8 then Click on the EasyPHP --->WWW---> index1.php. Write code in note pad and then follow the following procedure and save it with name index1.php as i give it name as a example.After saving your page (code) in EasyPhp-->www folder then go to explorar and write localhost or 127.0.0.1
Let's start now
// this is the php ending tag
Here are some examples
The Output
20
$b = "Banana's" ;
echo $a, $b;//We can print multiple items by separating them using a comma
The Output
20 Banana's
IF Statements
//If statements as same as in C,C++,JAVA,ASP etc
$x = 1o ;
$y = 20 ;
if($x< $y) { echo "True" ; //If IF condition is true mean's X less then Y then it will enter's here } else { echo "False"; //If IF condition is false mean's X not less then Y then it will enter's here } ?>
We can also use Html using php see the example.
Replace the "N" with "<" and "M" with ">" in the below html tags
echo "NhtmlM" ; // Here printing a HTML starting tag
echo "Na href="http://www.google.com/"MGoogleN/aM" ; // Here printing a HTML Hypertext Referrence line tag
echo "Ninput value="Firsttext" maxlength="100" type="text"M" ; // Here printing a HTML tag to input a text
echo "N/htmlM" ; // Here printing a HTML Ending tag
?>
The one more easier way to do the samework is to just close the php tag, type html and open the php tag again. An example would be a php if statement.
//close php tag here and starts html tags
Nform name="firstpage" method="post"M
Ninput name="name" type="text"M
Ninput name="Update" type="Update"M
N/formM
Let's Start Php Loops these loops are same as in C,C++,Java etc
for ($i=1; $i<=10; $i++) // for(intialization;condition;increments/decrements) { echo $i, "= "$i; // write your statements here } FOREACH LOOP using array
$array1=array("yellow","blue","red");
foreach ($array1 as $colors)
{
//we can use Concatination "." to split/join variables and strings together
echo "Color: " . $colors . "
";
}
While loop is same as in C,C++,Java etc
$i=1;//intialization we can do outside the loop in while loop;
while ( $i<=10) // while(condition) { echo $i, "= "$i; // write your statements here $i++;//increments/decrements }