Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Thursday, May 31, 2012

Creating a bus Image In PHP using Graphics


<?
$img=imagecreatetruecolor(600,600);
$grey=imagecolorallocate($img,200,191,191);
$brown=imagecolorallocate($img,152,50,50);

imagerectangle($img,245,155,516,253,$grey); //bus
imagerectangle($img,442,96,511,154,$grey); //top-square

imageline($img,244,172,516,172,$grey);
imageline($img,244,232,516,232,$white);

imagefilledrectangle($img,280,180,302,197,$grey); //window1
imagefilledrectangle($img,354,180,376,196,$grey); //window2
imagefilledrectangle($img,424,180,446,196,$grey); //window3

imagefilledellipse($img,295,275,50,50,$brown); //wheel left-outer
imagefilledellipse($img,295,275,20,17,$grey); //wheel left-inner
imagefilledellipse($img,440,280,50,50,$brown); //wheel right-outer
imagefilledellipse($img,440,280,20,17,$grey); //wheel right-inner

header('Content-Type:image/png');
imagePNG($img);
imagepng($img,"t4.png");
imagedestroy($img);
?>

Creating a circle image in PHP using Graphics


<?php 

// create a 200*200 image 
$img = imagecreate(200, 200); 
  
// allocate some colors 
$white = imagecolorallocate($img, 255, 255, 255); 
  
// draw a white circle 
imagearc($img, 100, 100, 150, 150, 0, 360, $white); 

// output image in the browser 
header("Content-type: image/png"); 
imagepng($img); 
  
// free memory 
imagedestroy($img); 

?>

Thursday, May 24, 2012

To Count the Number of Vowels (PHP)


<?php

$s=$_POST['str'];

$cnt=0;

for($i=0;$i<strlen($s);$i++)
{

if($s[$i]=="a" || $s[$i]=="e" || $s[$i]=="i" || $s[$i]=="o" || $s[$i]=="u")
{
echo "<br>".$s[$i];
$cnt++;
}

}
"<br>"."No of vowels :  ";
echo $cnt;


/*
echo $_POST['nm'];
$class = $_POST['class'];

echo $class;
*/
?>


Saturday, May 19, 2012

Program name: write a PHP script: Given a flat file of student information student no, name, mark I, mark II, mark III. Read this file and print the mark list in tabular form. Mark list will contain Student no, Name, Mark I, Mark II, Mark III and percentage for all students(PHP)


<?php

if(file_exists("stud_1.dat"))
{
$fp = fopen("stud_1.dat","r");

if(!$fp)
echo "File opening Error";
else
{
$buf = fread($fp,filesize("stud_1.dat"));
$tempercs = explode("\n",$buf);
$i = 0;

       //echo $buf;
foreach($tempercs as $t)
if(strlen($t)>0)
$records[$i++] = explode(" ",$t);

echo "<p>************* Student Name ***************</p>";
echo "<table border=2>";
echo "<tr><th> Roll No </th><th> Name </th>
<th> Mark I </th>
<th> Mark II </th>
<th> Mark III </th>
<th> Percentage </th></tr>";



foreach($records as $rec)
{
//print_r($rec);
echo "<tr>";
$k = 1;
$tot = 0;
foreach($rec as $f)
{
printf("<td>%s</td>",$f);
$k++;


if($k>3)
$tot = $tot + $f;
}
$ptage = ($tot/3.0);
printf("<td>%2f</td></tr>",$ptage);
}
echo "<table>";
fclose($fp);
}

}
else
{
echo "Not Exist";
}
?>



Generating a circle in PHP (GRAPHICS)


<?php 


// create a 200*200 image 
$img = imagecreate(200, 200); 
  
// allocate some colors 
$white = imagecolorallocate($img, 255, 255, 255); 
  
// draw a white circle 
imagearc($img, 100, 100, 150, 150, 0, 360, $white); 


// output image in the browser 
header("Content-type: image/png"); 
imagepng($img); 
  
// free memory 
imagedestroy($img);

Sending Mail in PHP


<?php


$to = $_POST['to'];
$sub = $_POST['sub'];
$msg = $_POST['msg'];
$header = "From: chinmay_youthmail@yahoo.co.in";
$report = mail($to,$sub,$msg,$header);


if($report)
{
echo "Mail transfered successfully.......";
}
else
{
echo "There is error in sending mail....";
}
?>