PHP


(1) Print Hello World.

                                    Here we can use Echo method for Print hello world message.
           
Syntax:           

echoWrite down Any Message with double quota You Want Display it “;

            Example:

                        <? Php
                                    Echo “Hello World “;
?>

Output:
            Hello World

(2) How to declare variable and store value on that variable.
         
                        Here there is no keyword use for declare php variable. Here $ sign is use for declare variable. Php is automatically known that which type of value stored on that variable.

            Syntax for declare variable:

                                        $<Variable name>;

                Example:
                                                $Name;
                                                $name;
                                                $_1;
                                               
            Note: Php is CaseSencetive So Capital and Small Variable Both Are Different.

            Syntax for store value in variable:
                                   
                                    $<Variable Name>=value;
               
                Example:
                                    $Name = “Natural IT Solution”;
                                                $name=”Php Programming”;
                                                $_1=123;
               


                Program 2:
                                               
                                <? Php
$Name = “Natural IT Solution”;
                                                $name=”Php Programming”;
                                                                                               
                                                Echo “Name is : - “;
                                                Echo $Name;
                                               
                                                Echo “<br>”;            
                                               
                                                Echo “name is:-”. $Name;
                                               
?>

(3) Conditional Statement.

There is various Conditional Statement Available in Php Like,
1.        If
2.        If Else
3.        Nested If
4.        Switch Case                                 

(1)     If Conditional Statement :

                                                   This statement is useful when given condition is true then Statement Code will be execute.

            Syntax:                                              
                                If (Expression)
                                {
                                                     Statement Code to Be Execute;
                              }

                Program 3:

                <? Php
                //Find Maximum Number
               
                $A = 10;
                $B = 15;                                                                                                               
               
                If ($A>$B)
                {
                      echo “A Is Maximum”. $A;
                }

                ?>



(2)     If Conditional Statement :
                                                                                                This statement is useful when given condition is true then True Statement Code will be execute Else False Statement code Will be execute.

Syntax:                                                              
                            If (Expression)
                            {
                                                True Statement Code to Be Execute;
                          }
                                            Else
                          {
                                                False Statement Code to Be Execute;

                           }
Program 4:

                <? Php
                //Find Maximum Number
               
                $A = 10;
                $B = 15;                                                                                                               
               
                If ($A>$B)
                {
                      echo “A Is Maximum”. $A;
                }
                Else
              {
                      echo “B Is Maximum”. $B;
              }

                ?>


(3)     Nested If Conditional Statement :
                                                                                                This statement is useful when given multiple conditions; Code will be executed when one Condition is True Otherwise Else Statement Code will be executed.

Syntax:                                                              
                            If (Expression)
                            {
                                                True Statement Code to Be Execute;
                          }
                                           Else If (Expression)
                          {
                                                True Statement Code to Be Execute;

                           }
                                          Else (Expression)
                          {
                                                False Statement Code to Be Execute;

                          }

Program 5:

                <? Php
                //Find Maximum Number
               
                $A = 10;
                $B = 15;                                                                                                               
                $C = 5;
                If ($A>$B && $A>$C)
                {
                      echo “A Is Maximum”. $A;
                }
                Else if ($B>$C)
              {
                      echo “B Is Maximum”. $B;
              }
                Else
                {
                      echo “C Is Maximum”. $C;
                }

                ?>

(4)     Switch Case Conditional Statement :
                                                                                                This statement is useful when given multiple Cases; Code will be executed when one Case is Match otherwise default Statement Code will be executed.


Syntax:
        
         Switch (Expression)
            {
            Case 1:
                       Statement code;
                       Break / continue;
            Case 1:
                       Statement code;
                       Break / continue;
            Case 1:
                       Statement code;
                       Break / continue;
            Default:
                       Statement code;
                       Break / continue;

            }



Program 6:

                <? Php
               
                //Find Number

            $NO=1;
           
            Switch ($NO)
            {
           
            Case 1:
                       Echo “One”;
                       Break;
            Case 2:
                       Echo “Two”;
                       Break;
            Case 3:
                       Echo “Three”;
                       Break;
            Case 4:
                       Echo “Four”;
                       Break;
            Case 5:
                       Echo “Five”;
                       Break;
            Case 6:
                       Echo “Six”;
                       Break;
            Case 7:
                       Echo “Seven”;
                       Break;
            Default:
                       Echo “Number Not Availabe”;
                       Break;

            }


                ?>

(4) Looping Statement.
There is various looping Statement Available in php Like,
                            1. For
                            2. While
                            3.  Do while


(1) For Loop:

Syntax:
        
                                For (declaration; condition/Expression; Inc/Dec)
                                {
                                         Statement;
                                }
                 
                 Example:
                               
                                <? Php

                                         For ($i=1; $i<=10; $i++)
                                              {
                                                    Echo “No Is: “. $i;
                                               }                                              

                                ?>
(2) While Loop:

Syntax:
        
                                While (Condition / Expression)
                                {

                                        Statement;
                                        (Increment/Decrement);
                                }
                 
                 Example:
                               
                                <? Php

                                While ($i<10)
                                {
                                      Echo”No is:” $i;
                                   $i++;
                                }
                                ?>
(3) Do While Loop:

Syntax:
        
                                Do
                                {

                                        Statement;
                                       (Increment/Decrement);

                                } while (Condition / Expression);

                 
              


  Example:
                               
                                <? Php
                                $i=1;
                                Do
                                {
                                      Echo”No is:” $i;
                                   $i++;
                                } while ($i<10);
                                ?>


(5)   Use Html Tag in PHP.

                  I think now, we all familiar with HTML.here the question is that how we can use All Html Tag in PHP. Below I will give some example so that you get the idea about all the html tag.

Example.

                <? Php
               
                           Echo”<b>Bold Tag</b>”;
                           Echo”<U>Underline Tag</b>”;            
                           Echo”<I>Italic Tag</I>”;
                           Echo”<input type=’text’ name=’txtname’/>”;                                                                                                                           Echo”<br>”;
                           Echo”<input type=’radio’ name=’gender’ value=’Male’>Male”;                   
                           Echo”<input type=’radio’ name=’gender’ value=’Female’>Female”;                             
                           Echo”<img src=’sunset.jpg’ alt=’sunset’></img> ”;                         

                ?>
(6)   Use JavaScript in PHP.
               
                Javascript is the one of the scripting language. Which we use with HTML.
 Javascript always Execute on client side. when we want any client validation then we ca use Javascript.
                                                                               

Example.

                <? Php
               
                           Echo”<b>Alert Box</b>”;
                           Echo”<script>”;                       
                           Echo” alert(‘JavaScript In Php’)”;                         
                           Echo”</script>”;                                      

                ?>


(7)   GET and POST Method in PHP.

(1)   $_GET :

·         The Get Method is useful when we want to transfer some value from One page to another page.
·         When we use this Get method , transfer value show on the address bar.
·         You can set this this method on form tag in method attributes.

Syntax:
                 $_GET [“Variable name”];

Example-(1):  Get.php

         <Html>
                                                                           
              <Head>
                                          <Title>Get Method Example</title>
             </head>
           
            <Body>

            <form action=”getdata.php” method=”GET”>
                                    
                       Name : <input type=”text” name=”txtname”/>

             </form>                                                           
           
            </body>
                                                                           
            </html>

Example-(2):  getdata.php

            <? Php

                                         Echo “Your name”. $_GET [“txtname”];                            


            ?>



(2)   $_POST :

·         The POST Method is useful when we want to transfer important data from One page to another page.
·         When we use this POST method ,the  transfer value dont show on the address bar.
·         You can set this this method on form tag in method attributes.

Syntax:
                 $_POST[“Variable name”];

Example-(1):  Post.php

         <Html>
                                                                           
              <Head>
                                          <Title>POST Method Example</title>
             </head>
           
            <Body>

            <form action=”postdata.php” method=”post”>
                                    Name : <input type=”text” name=”txtname”/>
             </form>                                                           
           
            </body>
                                                                           
            </html>

Example-(2): postdata.php

            <? Php

                                        Echo “Your name”. $_POST [“txtname”];                           

                                 ?>