Sunday, 20 September 2009

Create A JPG

//create an image 400 by 200 pixels
$img = imagecreate(400,200);
//set variable $red to be red
$red = imagecolorallocate($img,255,0,0);
//draw a rectangle
Imagerectangle($img,50,50,150,150,$red);
//create a gif
ImageJPEG($img,"pic.jpg");
//clean up resources
ImageDestroy($img);
?>

Thursday, 17 September 2009

Redirect to a different URL

header('Location: http://www.google.com');
exit();
?>

Wednesday, 16 September 2009

A Class example

class firstclass
{
function sayHello()
{
print"Hello world";
}
function sayGoodbye()
{
print"Goodbye";
}

}
?>
$obj = new firstclass();
$obj->sayhello();
$obj->sayGoodbye();
?>

Tuesday, 15 September 2009

Set Cookie example

setcookie('color','green');
?>

Create a PNG

$img = imagecreate(400,200);
$red = imagecolorallocate($img,255,0,0);
Imagerectangle($img,50,50,150,150,$red);
ImagePNG($img,"pic.png");
ImageDestroy($img);
?>

Search an array

$sites = array("Google", "yahoo" ,"programmershelp");
$search = array_search("Google",$sites);
if($search)
{
echo "The site exists";
}
else
{
echo "Cant find that site";
}

?>

Reverse an array

//declare an array
$list = array("a","b","c","d","e");
//print the array
print_r ($list);
print "
";
//reverse the array and print the array contents again
print_r (array_reverse($list));
?>

array_push example

$sites = array("Google", "yahoo" ,"programmershelp");
print_r ($sites);
print "
";
array_push($sites, "microsoft","bbc");
print_r($sites);
?>

Count items in an array

$sites = array("Google", "yahoo" ,"programmershelp");
print count($sites);
print "
";
array_push($sites, "microsoft","bbc");
print count($sites);
print "
";

?>