Saturday, 6 October 2012

Do while loop in php

// Do While loop in php

Syntax

do
{
code to be executed;
}while (condition); 
 
 
<?php
//print 1 to 10 number
$a = 1; 
do
echo "<br>".$a; 
 $a++; 
}while( $a < 10 );

?>
 

Do while loop in php


While loop in php examples



//  How to use while loop in php.


Syntax

while (condition)
{
code to be executed;
}
 
 
<?php
// print  1 to 5  
$a=1;
while ($a<=5)
{
echo "\t ".$a;
$a=$a+1;
 
} 
 
?> 

Type of loop in php

There is mainly four type of loops.
Loops  are used to execute the same block of code a specified number of times in php.
 
1. for loop.
2. while loop.
3. Do-while loop.
3. foreach loop.


Syntax


for (initialization; condition; increment)
{
code to be executed;
}


<?php 
// print  1 to 10 number 
for( $i=0; $i<10; $i++ )
{
echo "<br>".$i;
 
}
///////////////////
 
 
//Sum of ten number 
 
 
$sum = 0;
for( $i=0; $i<10; $i++ )
{
echo "<br>".$i;
$sum=$sum+$i;
}

echo " Total of 10 number =".$sum;
 
?> 



Saturday, 11 August 2012

File Upload with php

we must first create an HTML form that lets users select a file for uploading.

Remove whitespace from both sides of a string with php

//Remove whitespace from both sides of a string in php

function removeSideSpace($str)
{

return trim($str);

}

$yourString="  This  is test for the string    ";

echo " <br> Before remove the space == ".strlen($yourString);

$yourString= removeSideSpace($yourstring);

echo " <br> After remove the space == ".strlen($yourString);


?>

How to Redirect any page with php

<?php

//how  to Redirect any page with php




function  reDirect2Url($pageUrl) //  Write the function code Here
{
    if ($pageUrl!="")
    {
        header("location: $pageUrl");
    }
}



reDirect2Url("yourpageurlhere");   // called the function

?>
Freelance Jobs