Tuesday, October 21, 2014

String function in php


 <?php  
      $sentence = "I lob to have tea but some time I prefer coffee";  
      //replacing tea from above sentence by milk with str_replace function  
      echo str_replace("tea","milk",$sentence);  
 ?>  

Regular expression example 3


 <?php  
      // type of regular expression  
      //posix style regular exrpession  
      //pcre style regular expression  
      $sentence = "I lob to have tea but some time I prefer coffee";  
      $regexp="love|lob|feelings";  
      // search the search the mentioned words in the sentence  
      if(ereg($regexp,$sentence))  
      {  
           echo "regular expression is true";  
      }  
      else  
      {  
           echo "regular expression is false";  
      }  
 ?>  

Regular expression example 2


 <?php  
      // type of regular expression  
      //posix style regular exrpession  
      //pcre style regular expression  
      $sentence = "I lob to have tea but some time I prefer coffee";  
      //^ search the lob word in the begining of the sentence  
      if(ereg("^lob",$sentence))  
      {  
           echo "regular expression is true";  
      }  
      else  
      {  
           echo "regular expression is false";  
      }  
 ?>  

Regular expression example 1


 <?php  
      // type of regular expression  
      //posix style regular exrpession  
      //pcre style regular expression  
      $sentence = "I lob to have tea but some time I prefer coffee";  
      if(ereg("lob",$sentence))  
      {  
           echo "regular expression is true";  
      }  
      else  
      {  
           echo "regular expression is false";  
      }  
 ?>  

Sunday, October 5, 2014

Get form data (get method)

1:  <?php  
2:       $test = $_GET["test"];  
3:       $test2 = $_GET["test2"];  
4:       echo $test;  
5:       echo "</br>".$test2;  
6:       $len = strlen($test);  
7:       if($len > 0)  
8:       {  
9:            echo "</br>".$len + strlen($test2);  
10:       }  
11:       else  
12:       {  
13:            echo "error : there is no input";  
14:       }  
15:  ?>  
16:  <form method = "GET" action = "Basic3.php">  
17:       <input type= "text" name="test" >  
18:       <input type="text" name="test2">  
19:       <input type="submit" value="submit">  
20:  </form>  

Posting form data (post method)

1:  <?php  
2:       $temp = Array("one","two","cow","toe");  
3:       echo count($temp);  
4:       echo "</br>" . $temp[1];  
5:       for($i=0 ; $i < count($temp) ; $i++)  
6:       {  
7:            echo "</br>Loop #$i $temp[$i]" ;  
8:       }  
9:       $var =5;  
10:       if ($var == 4)  
11:       {  
12:            echo "value is 4";  
13:       }  
14:       elseif ($var == 5)  
15:       {  
16:            echo "value is 5";  
17:       }  
18:  ?>  

Array


1:  <?php  
2:       $temp = Array("one","two","cow","toe");  
3:       echo count($temp);  
4:       echo "</br>" . $temp[1];  
5:       for($i=0 ; $i < count($temp) ; $i++)  
6:       {  
7:            echo "</br>Loop #$i $temp[$i]" ;  
8:       }  
9:       $var =5;  
10:       if ($var == 4)  
11:       {  
12:            echo "value is 4";  
13:       }  
14:       elseif ($var == 5)  
15:       {  
16:            echo "value is 5";  
17:       }  
18:  ?>