Internet Technology
Internet Technology
Ans. <?php
function check_prime($num)
{
if ($num == 1)
return 0;
for ($i = 2; $i <= $num/2; $i++)
{
if ($num % $i == 0)
return 0;
}
return 1;
}
$num = 47;
$flag_val = check_prime($num);
if ($flag_val == 1)
echo "It is a prime number";
else
echo "It is a non-prime number"
?>
Output
1|Page
2. Write a PHP script to display all Fibonacci sequence with HTML page.
Ans. <!DOCTYPE html>
<html>
<head>
<title>Fibonacci Sequence</title>
</head>
<body>
<h1>Fibonacci Sequence</h1>
<?php
$n = 10;
$fib1 = 0;
$fib2 = 1;
echo "Fibonacci Series: ";
for ($i = 0; $i < $n; $i++) {
echo $fib1 . " ";
$next = $fib1 + $fib2;
$fib1 = $fib2;
$fib2 = $next;
}
?>
</body>
</html>
Output
2|Page
3. Write a PHP script to find a Factorial of a number.
Ans. <?php
$num = 4;
$factorial = 1;
for ($x=$num; $x>=1; $x--)
{
$factorial = $factorial * $x;
}
echo "Factorial of $num is $factorial";
?>
Output
3|Page
5. Write a PHP program that inserts a new in an array in any position.
Ans. <?php
4|Page
6. Write a PHP script to count number of elements in an array and display
a range of array elements.
Ans. <?php
$array = array("Apple", "Banana", "Cherry", "Date", "Elderberry", "Fig",
"Grape");
$count = count($array);
echo "Total number of elements in the array: $count\n";
$start = 2;
$end = 5;
if ($start >= 0 && $end < $count && $start <= $end) {
echo "Elements from index $start to $end:\n";
for ($i = $start; $i <= $end; $i++) {
echo "Index $i: " . $array[$i] . "\n";
}
} else {
echo "Invalid range specified.\n";
}
?>
Output
5|Page
7. Write a PHP function to check whether all array values are string or not.
Ans. <?php
function check_strings_in_array($arr)
{
return array_sum(array_map('is_string', $arr)) == count($arr);
}
$arr1 = array('PHP', 'JS', 'Python');
$arr2 = array('SQL', 200, 'MySQL');
var_dump(check_strings_in_array($arr1));
var_dump(check_strings_in_array($arr2));
?>
Output
8. Design a HTML page describing an ordered list where the serial number
begin from 1-5.
Ans. <!DOCTYPE html>
<html>
<head>
<title>Ordered List</title>
</head>
<body>
<h1>Ordered List</h1>
6|Page
<ol>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
</ol>
</body>
</html>
Output
7|Page
<style>
table {
border-collapse: collapse;
width: 100%;
font-family: Arial, sans-serif;
font-size: 14px;
}
th, td {
border: 1px solid black;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<h1>Places Visited</h1>
<table>
<tr>
<th>Date</th>
<th>Country</th>
<th>Purpose</th>
</tr>
<tr>
<td>Dec 25, 2020</td>
8|Page
<td>Singapore</td>
<td>Quarterly Review Meeting</td>
</tr>
<tr>
<td>Dec 26, 2022</td>
<td>Taiwan</td>
<td>Branch Managers Meeting</td>
</tr>
<tr>
<td>Dec 27, 2022</td>
<td>Japan</td>
<td>Get Together</td>
</tr>
</table>
</body>
</html>
Output
9|Page
10. Design a HTML page with your college name where the font color will
be RED and font size will be '16' and background colour will be GREEN.
Ans. <!DOCTYPE html>
<html>
<head>
<title>College Name</title>
<style>
body {
background-color: green;
font-size: 16px;
color: red;
}
</style>
</head>
<body>
<center><h1>Global College of Science and Technology</h1></center>
</body>
</html>
Output
10 | P a g e