Saturday 14 March 2015

Star-Shape using PHP

Three types of star shape using PHP
Just unrar the rar file into your Localhost and run through Apache Server using Browser
Select your shape and input the number of rows
Then press the Enter button.



HTML
<!DOCTYPE HTML>
<html lang="en-US">
<link rel="stylesheet" href="style.css" />
<head>
 <meta charset="UTF-8">
 <title>Star Shape</title>
</head>
<body>
 

<form action ="a.php" method="get">
<table>
<tr>
 <th align="left">Shape:</th>
 <td>
   <input type="radio" name="shape" value="1"><img src="triangle1.jpg"/></input>
   <input type="radio" name="shape" value="2"><img src="triangle2.jpg"/></input>
   <input type="radio" name="shape" value="3"><img src="triangle4.jpg"/></input>
 </td>
</tr>
<tr>
<div class="row"><th>Rows: </th></div>
<td><input type="text" name="row"/></td>
</tr>

<tr>
<th/>
<div class="create"><td><input type="submit" name="create" value="Create" /></td></div>

</table>

</form>

</body>
</html> 
 

<?php

echo "Number of rows: ";echo $_GET["row"];
echo "</br>";echo "</br>";
if ($_GET["row"]<1 OR $_GET["shape"]== "")
{
echo "Invalid input or Selection.try again";
die();
}


 switch ($_GET["shape"])
 {
 case "1":
  {
   for($i=1;$i<=$_GET["row"]; $i++)
   {
    for($j=1;$j<=$i;$j++)
    {
     echo "*";
    }
   echo "</br>";
   }
  break;
  }
 
 case "2":
  {
   for($i=1;$i<=$_GET["row"]; $i++)
   {
    for($j=$i;$j<=$_GET["row"];$j++)
    {
     echo "&nbsp";
    }
    for($k=1;$k<=$i;$k++)
    {
     echo "*";
    }
   echo "</br>";
   }
   
  break;
 
 }
 case "3":
  {
   for($i=1;$i<=$_GET["row"]; $i++)
   {
    for($j=$i;$j<=$_GET["row"];$j++)
    {
     echo "&nbsp";echo "&nbsp";
    }
    for($k=1;$k<=$i;$k++)
    {
     echo "*";
    }
   echo "</br>";
   }
   
  break;
 
 }
}



?>
Click Here to Download

0 comments:

Post a Comment

 

Subscribe to our Newsletter

Contact our Support

Through the contact form

Our Team Memebers