You are on page 1of 7

Muhammad Aashir Khan

02-134201-032 lab-9 intro to php

EXERCISE 1:

1. Write PHP program to convert a string, lower to upper case and upper case to
lower case or capital case.

CODE:

SS:
Muhammad Aashir Khan
02-134201-032 lab-9 intro to php

2. Check whether the given number is Palindrome or not.

<html>
<body>
<form method="post">
Enter a Number: <input type="text" name="num"/><br>
<button type="submit">Check</button>
</form>
<?php if($_POST)
{
$num = $_POST['num'];
$reverse = strrev($num);
if($num == $reverse){
echo "The number $num is Palindrome";
}else{
echo "The number $num is not a Palindrome";
}
}
?>
</body>
</html>

EXERCISE 2:

Write a php program that generate the marks sheet of a student. Store the information of the
student and its marks using associative array. Display the information in an Html table.

CODE:
<?php
$STUDENT_INFO = array(
'name' => 'Hafsah',
'maths' => 90,
'physics_th' => 60,
'physics_pr' => 18,
Muhammad Aashir Khan
02-134201-032 lab-9 intro to php

'english' => 80,


'chem_th' => 60,
'chem_pr' => 15,
'pst' => 77,
);
?>
<!DOCTYPE html>
<html>
<head>
<title>MARKS SHEET USING HTML TABLES</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="Keywords" content="html, css, html tables, table">
<meta name="Description" content="html table">
<!-- add icon -->
<link rel="icon" href="/favicon.ico" type="image/x-icon">
<style> body{
background-color: #c5cae9;
padding: 25px;
}
.container{

width: 750px; height: 400px ; margin: 0 auto; padding-left: 32px; padding-right:


32px; padding-top: 40px; border-radius: 12px; background-color: #90a4ae;
font-family: Lato;
}
.container h2{ text-align: center;
text-decoration: underline;
} table{
margin: 0 auto; text-align: center;
} td, th { padding: 12px; border: 2px dotted;
Muhammad Aashir Khan
02-134201-032 lab-9 intro to php

}
</style>
</head>
<body>
<div class="container">
<h2>Mark Sheet</h2>
<table>
<thead>
<tr>
<th>No.</th>
<th>Subject Name</th>
<th>Total Marks</th>
<th>Theory</th>
<th>Practical</th>
<th>Obtained Marks</th>
<th>Grade</th>
<tr>
</thead>
<tbody>
<tr>
<td>01</td>
<td>Maths</td>
<td>100</td>
<td><?php echo $STUDENT_INFO['maths'] ?> out of 100</td>
<td></td>
<td><?php echo $STUDENT_INFO['maths'] ?></td>
<td>A+</td>
</tr>
<tr>
<td>02</td>
<td>English</td>
Muhammad Aashir Khan
02-134201-032 lab-9 intro to php

<td>100</td>
<td><?php echo $STUDENT_INFO['english'] ?> out of 100</td>
<td></td>
<td>80</td>
<td>A</td>
</tr>
<tr>
<td>03</td>
<td>Physics</td>
<td>100</td>
<td><?php echo $STUDENT_INFO['physics_th'] ?> out of 80</td>
<td><?php echo $STUDENT_INFO['physics_pr'] ?> out of 20</td>
<td><?php echo ($STUDENT_INFO['physics_th']+
$STUDENT_INFO['physics_pr'])?></td>
<td>B</td>
</tr>
<tr>
<td>04</td>
<td>Chemistry</td>
<td>100</td>
<td><?php echo $STUDENT_INFO['chem_th'] ?> out of 80</td>
<td><?php echo $STUDENT_INFO['chem_pr'] ?> out of 20</td>
<td><?php echo ($STUDENT_INFO['chem_th']+
$STUDENT_INFO['chem_pr'])?></td>
<td>B</td>
</tr>
<tr>
<td>05</td>
<td>Pakistan Studies</td>
<td>100</td>
<td><?php echo $STUDENT_INFO['pst'] ?> out of 100</td>
Muhammad Aashir Khan
02-134201-032 lab-9 intro to php

<td></td>
<td>71</td>
<td>B</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>

SS:

EXERCISE 3:

Write an HTML document that includes anchor tag that calls a PHP document. Also write the
called PHP document, which returns a randomly chosen greeting from the a list of five different
Muhammad Aashir Khan
02-134201-032 lab-9 intro to php

greetings. The greetings must be stored as constant strings in the script. A random number
between 0 and 4 can be computed with these lines.

#set the seed for mtrand with the number of microseconds


#since the last full second of the clock
mt_srand((double)microtime() * 1000000);
$number = mtrand(0,4); #computes a random integer 0 -4
html>
<head>
<title>Greetings</title>
</head>
<body>
<h2>
<a href ="greeting.php">Display Greeting</a>
</h2>
</body>
</html>
<?php
$greeting = array(
0 => "Happy Birthday",
1 => "Happy Winter Holidays",
2 => "Happy New Year",
3 => "Happy Eid",
4 => "Best of luck!"
);
$n = mt_rand(0,4);
echo $greeting[$n];
?>

SS:

You might also like