AIM:-Write Programme in PHP 1. Write a PHP program to print your basic details.
Snapshot:-
Code:<html> <head> <head> <body bgcolor="yellow"> <?php echo"<h1><b><u>Basic Details</u></b></h1> "; echo"Name:- Sanket j.shah<br>"; echo"Enrollment No:- 110753116008<br>"; echo"Semester:-6<br>"; echo"Year:- 2012-13"; ?> </body> </html>
2. Write a PHP program to make a calculator. You can enter numbers from HTML page and transfer to PHP page. Snapshot:-
[Cal.php] Code:Cal.php <html> <head> </head> <body bgcolor="lightgreen"> <form method="get" action="calc1.php"> <center> <h1>Calculator</h1> <hr> <h3>Enter First Value:-
[Cal1.php]
<input type="text" name="t1"><br><hr>
<h3>Enter Second Value:- <input type="text" name="t2"><br><hr> <input type="Submit" value="+" name="choice"> <input type="Submit" value="-" name="choice"> <input type="Submit" value="*" name="choice"> <input type="Submit" value="/" name="choice"> <input type="Reset" value="Reset"> </center> </form> </body> </html>
Cal1.php <html> <head> </head> <body bgcolor="lightpink"> <center> <hr> <h1> Your Ans is: <?php $first=$_GET['t1']; $second=$_GET['t2']; $choice=$_GET['choice']; switch($choice) { case '+': { echo $first+$second; break; } case '-': { echo $first-$second; break; } case '*': { echo $first*$second; break; } case '/': { echo $first/$second; break;
} } ?> </h1> <hr> <a href="cal.php">GoBack</a> </center> </body> </html> 3. Write a PHP program to print reverse number. Snapshot:-
[p3.php] Code:<html> <head> </head> <body bgcolor="yellow"> <form method="get" action="p5.php"> <center> <table border="0"> <tr>
[p5.php]
<td><form>Number:<input type="text" name="t"></td> <td><input type="submit"value="submit" ></td> </tr> <table> </form> </center> </font>
</body> </html> P5.php <?php $num = $_GET["t"]; $revnum=0; do{ $revnum=($revnum *10)+($num % 10); $num=(int)($num / 10 ); }while($num>0); echo "Your Reverse number is $revnum"; ?>
4. Write a PHP program to print sum of digit Snapshot:-
[p3.php] Code:P3.php <html> <head> </head> <body bgcolor="yellow"> <form method="get" action="p4.php"> <center> <table border="0"> <tr>
[p4.php]
<td><form>Number:<input type="text" name="t"></td>
<td><input type="submit"value="submit" ></td> </tr> <table> </form> </center> </font> </body> </html> P4.php <?php $sum=0; $d; $n; $t=$_GET["t"]; $m=&$t; while($t>0) { $d = $t % 10 ; $t = $t / 10 ; $sum = $sum + $d; } echo "Your sum of digit $sum"; ?> 5. Write a PHP program to print factorial number. Snapshot:-
[p3.php]
[p2.php]
Code:P3.php <html> <head> </head> <body bgcolor="yellow"> <form method="get" action="p2.php"> <center> <table border="0"> <tr> <td><form>Number:<input type="text" name="t"></td> <td><input type="submit"value="submit" ></td> </tr> <table> </form> </center> </font> </body> </html> P2.php <?php $num = $_GET["t"]; $factorial = 1; for ($x=$num; $x>=1; $x--) { $factorial = $factorial * $x; } echo "Factorial of $num is $factorial"; ?>