html5andphp: Php example

Showing posts with label Php example. Show all posts
Showing posts with label Php example. Show all posts

Saturday, 22 November 2014

Special loop keyword



How to use special loop keyword :- continue and break



There are two special keyword available for looping

1. Continue 

2. Break


Continue :- Continue keyword is used to continue the block of code while condition is false following example explain the concept of continue and break keyword.




<?php
for ($i = 1; $i < 10; $i++)
{
if ($i == 5)
{
echo("Loop continued at $i<BR>");
continue;
}
if ($i == 8)
{
echo("Loop terminated at $i<BR>");
break;
}
echo("Number $i<BR>");
}
?>



Break:- Break keyword is used for unconditional jump, above example explain the concept of break keyword.



If you want to learn more about php visit php tutorial and download php basic tutorial 

Thursday, 13 November 2014

how to embed php into html




How to embed PHP into html

<html>
<head>
<title>html embeded code</title>
</head>
<?php
echo "welcome to the php";
echo "<br />";
echo "Html and php script embed<hr>";
echo "<b>"."hello friends"."<b>";
?>
<body>
</body>
</html>

Explanation

You can put your PHP script anywhere in our html code. Above example explain the following concept.

Another example of php into the html

<html>

<head>

<title>


<?php

echo "Title of your page";

 ?>

</title>

</head>

<body>

<?php

echo "welcome to the php";

echo "<br />";

echo "Html and php script embed<hr>";

echo "<b>"."hello friends"."<b>";

?>



</body>

<?php

echo "web come to php" ?>
</html>

explaination

Note :You can put php script any number of times in your html page like that.

If you want to learn more about visit

php tutorial

Download PHP PDF php basic tutorial

Sunday, 4 August 2013

Changing image using php random function

Random function in image

In this code simpl use of random function and switch case.First of all random function call in switch case and pass the initial and final value of case such as no of cases =16( 1 to 16 ) then first orgument is 1 and second orgument is 16 and seprated by comma.Then starting a switch case curly braces  and then start the first case,make a variable which store the the image same as all cases and assign the image and then use break keyword (break is used for stop a particular case ,if you don't use break all the case excuted and all the values ).Lastly print the variable which store the image using html img embed tag.

Check this code in your browser .
<?php

Download PHP PDF php basic tutorial pdf


echo "Making by umar farooque khan";
switch(rand(1,16))
{
   case 1:
$greet ="1.jpg";
break;
   case 2:
$greet ="2.jpg";
break;
   case 3:
$greet ="3.jpg";
break;
   case 4:
$greet ="4.jpg";
break;
case 5:
$greet ="a(1).jpg";
break;
   case 6:
$greet ="a(2).jpg";
break;
   case 7:
$greet ="a(3).jpg";
break;
   case 8:
$greet ="a(4).jpg";
break;


case 9:
$greet ="a(5).jpg";
break;
   case 10:
$greet ="a(6).jpg";
break;
   case 11:
$greet ="a(7).jpg";
break;
   case 12:
$greet ="a(8).jpg";
break;


case 13:
$greet ="a(9).jpg";
break;
   case 14:
$greet ="a(10).jpg";
break;
   case 15:
$greet ="a(11).jpg";
break;
   case 16:
$greet ="a(12).jpg";
break;

}
echo"<img src='$greet' height='900px' width='1200px'>";
?>



For more on php visit php-tutorial

Thursday, 1 August 2013

Upload File Using Php

Making Upload File Script Using Php html and java script with validation


<pre><!DOCTYPE html>
<head>
</head>
<body></pre>  //use pre tag to not show these tags in server
<center>
< form action = " upload.php" method = " post " enctype = " multipart / form-data " 
name = " upload  " >
  < table width =" 200 " border = " 2 " cellspacing = " 2 " cellpadding = " 2 " >
    < tr >
      < td > Upload a file< /td >
      < td > < input name = " file " type = " file "  / > < / td >
    < / tr >
    < tr >
      < td colspan = " 2 " > < center >
          < input name = " sub " type = " submit " value = " upload " />
        < / center >< / td >
    </tr>
  </table>

</form>
</center>
</body>
</html>
<?php
error_reporting(0);
if(isset($_POST['sub'])) 
     { 
      $name=$_FILES['file']['name'];
 $type=$_FILES['file']['type'];
 $size=$_FILES['file']['size'];
 $tmp=$_FILES['file']['tmp_name'];
        
if($name=='')
{
echo"<script>alert('upload file')</script>";
exit();
}

if(( $type == "image/jpeg" )||($type=="image/gif")||($type=="image/png"))
{
if($size<=500000)
{
if (file_exists("upload file" . $_FILES["file"]["name"]))
 {
 echo $_FILES["file"]["name"] . " already exists. ";
 exit();
 }
 move_uploaded_file($tmp,"$name");
                      echo"<center> <font color='pink' ><h2>successfully uploaded</h2></font><br>".""."<img src=$name> </center>";   
   }
 
 else
 {
 echo"more size";
 }
 
}   
 else
 {
 echo"type not support";
 } 
 
 
 
 
 }

?>

For more php tutorial PHP-tutorial
Output

upload

Saturday, 27 July 2013

Making Counter Using Php

Making Counter using php and html with the help of file handling.

Cont your real visiter using this very simple counter.

<?php
error_reporting(0);
$file = file_get_contents("counter.txt");
$data=$file;
$newdata=$data+1;
$newfile=fopen("counter.txt","w");
fwrite($newfile,$newdata);
?>
<html>
<table width="auto" border="2" cellspacing="2" cellpadding="2" bgcolor="#00FFFF" bordercolor="#0000FF" >
  <tr>
    <td><?php echo $newdata;  ?></td>
  </tr>
</table>
</html>

Output



For more on php visit php-tutorial


Download PHP PDF php basic tutorial pdf


counter

Thursday, 25 July 2013

calculator

Making calculator using php

Html , php and java script codecode


<!DOCTYPE html>
<head>
</head>
 <br> <br> <br>
<center>
<table width="200"  border = "2"  bordercolor = "#000033"  bordercolor = "#FF00FF" >
  <tr>
    <td>
<table  border = "1"  bgcolor = "#FFFFFF"  width = "210" height = "30" >
  <tr>
    <td>
<?php
error_reporting(0);
if( isset ($_POST ['sub'] ) )
                {
     $value1 = $_POST ['val1'] ;
                 $value2 = $_POST ['val2'] ;
     $cal = $_POST ['cal'] ;
                                 If ( $value1 == '' )
                                 {
                                 echo " < script >  alert ( ' please enter value ' ) < / script > " ;
                                 exit() ;
                                 }
                                 If ( $value2 == '' )
                                 {
                                     echo " < script >  alert ( ' please enter value ' ) < / script > " ;
                                                  exit() ;
                                     }
               
              If ( $cal == '' )
                                 {
                                     echo " < script >  alert ( ' please enter value ' ) < / script > " ;
                                                  exit() ;
                                     }
                                                switch ( $cal )
                                                {
                                                 case  "+"  :
                                                 echo $value1 + $value2 ;
                                                break ;
                                               
                                                case  "-"  :
                                                 echo  $value1 - $value2 ;
                                                break ;
                                               
                                                case  "*"  :
                                                 echo  $value1 * $value2 ;
                                                break ;
                                               
            case  "/"  :
                                                 echo $value1 / $value2 ;
                                                break ;
                                                }
                }
?>
               
</td>
  </tr>
</table>
< center >< br >< br >< br >< strong >< font color="#0066FF" >Simple Umar Calculator< /font >< strong>
< body bgcolor = "#00FFFF" >
< form action = "cal.php"  method = "post" >
< table >
  <tr>
    <td> Value1: </td>
    <td> <input name = "val1"  type = "text" ></td>
  </tr>
    <td> Sign: </td>
    <td> <input name = "cal" type = "text"> </td>
  </tr>
  <tr>
    <td> Value2: </td>
    <td> <input name = "val2" type = "text" > </td>
  </tr>
  <tr>
  <tr>
    <td colspan = "2"> < center >< input name = "sub"  type = "submit" value =  "CaLcUlAtE" > </center> </td>
    </tr>
</table>
</form>
</center>

</td>
  </tr>
</table>
</center>



</body>
</html>



For more on php visit php-tutorial

Download PHP PDF php basic tutorial pdf

calculator
umar farooque khan

Monday, 24 June 2013

Square Pattern In Php

                          Making of square pattern using php

The given squire pattern is made from loop .There are four type of loop in php 
1. for loop
2.while loop
3. do while loop
4. foreach loop 
I will tell you about loop in next post .use this code make square pattern.

Html code

<html>
<head></head>

<body>

<br><br><br><br>
<?php
$a=6;
for ( $b = 1 ; $b <= 6 ; $b++ )
{
 echo"&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp ";
 for ( $c = 1 ; $c <= $a ; $c++ )
   { 
    echo"&nbsp ";//using for blank space
   }
    $a--;
      for ( $c = 1 ; $c <= 2*$b - 1 ; $c++ )
   {
         echo"*";
        }
      echo"<br>";
 }
 $w=1;
 for ( $d=6;$d>=1;$d-- )
{
  echo"&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp ";
for ( $e=1;$e<=$w;$e++ )
   { 
    echo"&nbsp ";
   }
    $w++;
      for ( $e=1;$e<=2*$d-1;$e++ )
   {
         echo"*";
        }
      echo"<br>";
 }
 echo"uk";
?>
</body>
</html>

Note:
Save this code using .php extention.






For more on php visit php-tutorial
                                   
                                                        square pattern
square

Arrow in php

                                        
                

                                    Making  Arrow Using Php





arrow



Html code

The given arrow pattern is made from loop .There are many for loop used to create this type of pattern.
That is nested loop . 
<!doctype html>
<html>
<head></head>
<body>
uk
<?php
for ( $b =1;$b<=9;$b++ )
{
 for ($c=1;$c<=$b;$c++)
   {
   echo"$c";
   }
echo"<br>";
 }

 for ($a=9 ;$a>=1;$a-- )
{
 for ($d=1;$d<=$a;$d++)
   {
   echo"$d";
   }
echo"<br>";
 }
?>
</body>
</html>
umar

uk

"; } for ($a=9 ;$a>=1;$a-- ) { for ($d=1;$d<=$a;$d++) { echo"$d"; } echo"
"; } ?>

Making Flage using loop in php


Loops in php

This type of flag creating using nested loops . Big deal of loops.          

flag                     


Php code



<!doctype html>
<html>
<head></head>
<body>

<?php
for ( $b =1;$b<=6;$b++ )
{
echo"&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp";
 for ($c=1;$c<=20;$c++)
   {
   echo"*";
 
   }
 
     echo"<br>";
 
 }

 for ($a=1;$a<=10;$a++)
   {
   echo"&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp";
   echo"***";
   echo"<br>";
   }

   $a=3;
for ( $b = 1 ; $b <= 4 ; $b++ )
{
 for ( $c = 1 ; $c <= $a ; $c++ )
   {
    echo"&nbsp &nbsp &nbsp";
}
    $a--;
      for ( $c = 1 ; $c <= 2*$b - 1 ; $c++ )
   {
         echo"***";
        }
      echo"<br>";
 }
 
?>
<b>uk</b>
</body>
</html>






For more on php visit php-tutorial