Web Tech Slip
Web Tech Slip
q1.write a php script to get the php version and configuration information.
ans:<?php
echo phpinfo();
?>
q2.design a html form to accept a string.write php script for the following.
a)write a function to count the total number of vowels from the script.
b)show the occurrences of each vowel from the script.
ans:<html>
<head>
<title>count vowels</title>
</head>
<body>
<form method="post" action="count_vowels.php">
<label for="inputstring">enter a string:</label><br>
<input type="text" id="inputstring" name="inputstring"><br><br>
<input type="submit" value="submit">
</form>
</html>
<?php
if($_SERVER["REQUEST_METHOD"]=="POST")
$intputstring=$_POST['inputstring'];
function countvowels($str){
$vowels=['a','e','i','o','u'];
$vowelcount=0;
$voweloccurrences=array_fill_keys($vowels,0);
for($i=0; $i<strlen($str);$i++){
if(in_array(strtolower($str[$i]),$vowels)){
$vowelcount++;
$voweloccurrences[strtolower($str[$i])]++;
}
}
echo"total nnumber of vowels:".$vowelcount."<br>";
echo"occurrences of each vowels:<br>";
foreach($voweloccurrences as $vowel=>$count){
echo strtoupper ($vowel).":".$count."<br>";
}
}
countvowels($inputstring);
}
?>
slip no:2
q1.write a php script to display student information on web page.
ans:<?php
echo "name:deepa pawar";
echo "class:s.y.b.c.a(sci)";
echo :college name:"mit acsc college,alandi";
?>
q2.write a php program to define interface shape which has two method as area() and volume().define
a constant pi.create a class cylinder implement this interface and calculate area and volume.
ans:<?php
interface shape{
public function area();
public function volume();
}
class cylinder implements shape {
const pi=3.14;
private $radius;
private $height;
public function
--construct($radius,$height){
$this->radius=$radius;
$this->height=$height;
}
public function area(){
return 2*pi*this->radius*(this->radius+this->height);
}
public function volume(){
return pi*this->radius*this->radius*this->height;
}
$cylinder=new cylinder(5,10);
echo "area of the cylinder:".
$cylinder->area()."square units\n";
echo "volume of the cylinder:".
$cylinder->volume()."cubic units\n";
?>
slip no:3
q.1 write a php script to display time table of your class(use html table tags in echo).
ans:<?php
$class_name = "SYBCA";
$days = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday");
$time_slots = array("8:00 AM - 9:00 AM", "9:00 AM - 10:00 AM", "10:00 AM - 11:00 AM", "11:00 AM - 12:00 PM", "1:00 P
slip no:4
q1.write a php script to declare 3 variables and print maximum among them.
ans:<?php
$a=10;
$b=20;
$c=30;
$max=max($a,$b,$c);
echo "the maximum value among $a,$b,and $c is:$max";
?>
q2.write a php script for the following: design a form to accept two strings.compare the two strings using both metho
string.accept the position from the user;form the 1st string are reversed.(use radio buttons)
ans:<html>
<body>
<h2>string comparison and manipulation</h2>
<form method="post">
<label>enter string 1:</label><br>
<input type="text" name="string1"><br><br>
<label>enter string 2:</label><br>
<input type="text" name="string2"><br><br>
<input type="radio" name="position" value="start" checked>append at the start<br>
<input type="radio" name="position" value="end" checked>append at the end<br>
<input type="submit" name="submit" value="compare and append">
</form>
<?php
if($_SERVER["REQUEST_METHOD"]=="POST")
$string1=$_post['string1'];
$string2=$_post['string2'];
$position=$_post['position'];
if($string1==$string2){
echo " strings are equal using == operator.<br>";
}else{
echo " strings are is not equal using == operator.<br>";
}
$comparison =strcmp($string1,$string2);
if($comparison==0){
echo " strings are equal using strcmp function.<br>";
}else{
echo " strings are is not equal using strcmp function.<br>";
}
if($comparison=="start"){
$result=$string2.$string1;
}else{
$result=$string1.$string2;
}
echo "result after appending:$result";
}
?>
</body>
</html>
slip no:5
q1.write a php script to check number 153 is armstrong or not.
ans:<?php
$no=153;
$num=$no;
$result=0;
while($num!=0)
{
$rem=$num%10;
$result=$result+($rem*$rem*$rem);
%num=$num/10;
}
if($result==$no)
echo " num is armstrong";
else
echo " num is not armstrong";
?>
q2.write a menu driven program to perform the following operations on an associative array:
a)display the elements of an array along with the keys.
b)display the size of an array.
ans:<html>
<body>
<h2>menu-driven program for associative array</h2>
<form method="post">
<p>select an operation:</p>
<input type="radio" name="operation" value="display">display elements of the array along with the keys<br>
<input type="radio" name="operation" value="size">display the size of the array<br><br>
<input type="submit" name="submit" value="perform operation">
</form>
<?php
$arr=array('key1'=>'value1','key2'=>'value2','key3'=>'value3');
if($_SERVER["REQUEST_METHOD"]=="POST")
$operation=$_post['operation'];
switch($operation){
case 'display':
echo "<h3>elements of the array with keys:</h3>";
foreach($arr as key=>$value)
echo "key: $key,value:$value<br>";
}
break;
case 'size':
$size=count($arr);
echo "<h3>size of the array:</h3>";
echo "the size of the array is:$size";
break;
default:echo "invalid operation selected";
}
}
?>
</body>
</html>
slip no:6
q1.write a php script to check whether accepted number is prime or not.
ans:<?php
$f = 0;
$n = $_POST['num'];
for ($i = 2; $i < $n; $i++) {
if ($n % $i == 0) {
$f = 1;
break;
}
}
if ($f == 1) {
echo "Number is not prime ", $n;
} else {
echo "Number is prime : ", $n;
}
?>
q2.write a ajax program to search student name according to the character typed and display list using array.
ans:<html>
<head>
<script>
function searchnames(){
var input=document.getelementbyid("search").value;
var xmlhttp=new xmlhttprequest();
xmlhttp.onreadystatechange=function(){
if(this.readystate==4 && this.status==200){
document.getelementbyid("result").innerhtml=this.responsetext;
}
};
xmlhttp.open("GET","search.php?input="+input,true);
xmlhttp.send();
}
</script>
<head>
<body>
<h2>search student names</h2>
<label>enter the character:</label>
<input type="text" id="search" onkeyup="searchnames()">
<div id="result"></div>
</body>
</html>
slip no:7
q1.design a html form to accept a string.write php function to reverse a string.
ans:<html>
<body>
<form action="slip17_1-1.php" method="post">
Enter the string :
<input type="text" name="ch">
<input type="submit" class="sub">
</form>
</body>
</html>
<?php
$ch = $_POST['ch'];
$ch1 = strrev($ch);
echo "Original string : ", $ch, "Revesed String : ", $ch1;
?>
q2.declare array.reverse the order of elements,making the 1st element last and last element 1st and similarly rearra
ans: <?php
$originalArray = array(1, 2, 3, 4, 5);
$reversedArray = array_reverse($originalArray);
echo "Original Array: " . implode(", ", $originalArray) . "<br>";
echo "Reversed Array: " . implode(", ", $reversedArray) . "\n";
?>
slip no:8
q1.design a htnl form to accept a string.write a php function that checks whether a passed string is a palindrome or n
ans:<html>
<body>
<form action="slip17_1-1.php" method="post">
Enter the string :
<input type="text" name="ch">
<input type="submit" class="sub">
</form>
</body>
</html>
<?php
$ch = $_POST['ch'];
$ch1 = strrev($ch);
if ($ch == $ch1) {
echo "GIven string is palidrom : ", $ch;
} else {
echo "Given string is not palidrom : ", $ch;
}
q2.declare a multidimensional array.display specific element from a multidimensional array.also delete given elemen
ray content).
ans: <?php
$multiArray = array(
array("Aarav", "Patel", 25),
array("Neha", "Sharma", 30),
array("Rahul", "Verma", 22),
);
echo "<h3>Original Array:</h3>";
printArray($multiArray);
$specificElement = $multiArray[1][2];
echo "<h3>Specific Element:</h3>";
echo "Value at \$multiArray[1][2]: $specificElement";
$rowToDelete = 0;
$columnToDelete = 1;
unset($multiArray[$rowToDelete][$columnToDelete]);
function printArray($array)
{
echo "<pre>";
print_r($array);
echo "</pre>";
}
?>
slip no:9
q1.write a php script to print following floyd's triangle.
1
23
456
7 8 9 10
ans:<?php
$a = 1;
for ($i = 1; $i < 6; $i++) {
for ($j = 1; $j < $i; $j++) {
echo $a . "\t";
$a++;
}
echo "<br>";
}
?>
q2.write a menu driven program to perform the following stack related operations.
a)insert an element in stack.
b)delete an element from stack.[hint:array_push(),array_pop()]
ans:refer slip no:19 q2
slip no :10
q1.write a php code to display source code of a webpage.
ans:<?php
$all_lines = file('https://github.io/harshaldaundkar1513/mitacs');
foreach ($all_lines as $line_num => $line) {
echo "line no : {$line_num} : " . htmlspecialchars($line) . "\n";
}
?>
or <?php
show_source("student.php");
?>
Q2. Write a menu driven program to perform the following queue related operations
d) Insert an element in queue
e) Delete an element from queue
f) Display the contents of queue
ans:<?php
$ch = $_POST['ch'];
$queue = array();
switch ($ch) {
case 1:
$element = $_POST['num'];
array_push($queue, $element);
echo "Element inserted into the queue: $element\n";
break;
case 2:
$deletedElement = array_shift($queue);
echo "Element deleted from the queue: $deletedElement\n";
break;
case 3:
echo "Contents of the queue: " . implode(', ', $queue) . "\n";
break;
case 4:
echo "Exiting program.\n";
exit;
default:
echo "Invalid choice. Please enter a number between 1 and 4.\n";
}
?>
slip no:11
q1.Write a PHP script to get the PHP version and configuration information.
ans: refer slip no 1..q.1
q2.Design a HTML form to accept a string. Write a PHP script for the following.
a) Write a function to count the total number of Vowels from the script.
b) Show the occurrences of each Vowel from the script. -->
ans:<html>
<body>
<form method="post" action="count_vowels.php">
<label for="inputstring">enter the string:</label><br>
<input type="text" id="inputstring" name="inputstring"><br><br>
<input type="submit" value="submit">
</form>
</body>
</html>
<?php
if($_SERVER["REQUEST_METHOD"]=="POST")
$inputstring=$_post['inputstring'];
function countvowels($str){
$vowels=['a','e','i','o','u'];
$vowelcount=0;
$voweloccurrences=array_fill_keys($vowels,0);
for($i=0;$i<strlen($str);$i++){
if(in_array(strtolower($str[$i]),$vowels)){
$vowelscount++;
$voweloccurrences[strtolower($str[$i])++;
}
}
echo "total number of vowels".$vowelcount.<br>";
echo "occurrences of each vowel:<br>";
foreach($voweloccurrences as $vowel=>$count){
echo $vowel.":".$count.<br>";
}
}
countvowels($inputstring);
}
?>
slip no:12
q1.Write a PHP script to display student information on web page.
ans.refer slip no.2 q1
switch ($ch) {
case 1:
echo "The additon is : " . $num1 + $num2;
break;
case 2:
echo "The subtraction is : " . $num1 - $num2;
break;
case 3:
echo "The multiplication is : " . $num1 * $num2;
break;
case 4:
echo "The division is : " . $num1 / $num2;
break;
default:
echo "Invalid input";
}
?>
slip no:13
q.1 Write a PHP script to script to display time table of your class( use HTML table tags in echo).
ans: refer slip no.3 q1
q2.write a php script for the following:design a form to accept the details of 5 different items,
such as item code,item name,units sold,rate.display the bill in the tabular format.use only 4text
boxes.(hint:use of explode function.)
ans:refer slip no.3 q2.
slip no:14
q.1write a php script to declare 3 variables and print maximum among them.
ans refer slip no.4 q1
q2.write a php script for the following: design a form to accept two strings.compare the two strings using both metho
string.accept the position from the user;form the 1st string are reversed.(use radio buttons)
ans: refer slip no.4 q2
slip no:15
q1.write a php script to check number 153 is armstrong or not.
ans: refer slip no.5 q1
q2.create a xml file which gives details of students admitted for different courses in your college.course name can be
elements in each course are in following format.
<course>
<level>...</level>
<intake capacity>....</intake capacity>
</course>
save the file with"course.xml"
ans:<?xml version="1.0" encoding="UTF-8"?>
<College>
<Course>
<Name>Arts</Name>
<Details>
<Level>Undergraduate</Level>
<IntakeCapacity>100</IntakeCapacity>
</Details>
</Course>
<Course>
<Name>Science</Name>
<Details>
<Level>Undergraduate</Level>
<IntakeCapacity>120</IntakeCapacity>
</Details>
</Course>
<Course>
<Name>Commerce</Name>
<Details>
<Level>Undergraduate</Level>
<IntakeCapacity>80</IntakeCapacity>
</Details>
</Course>
<Course>
<Name>Management</Name>
<Details>
<Level>Postgraduate</Level>
<IntakeCapacity>60</IntakeCapacity>
</Details>
</Course>
</College>
slip no:16
q1.write a php script to check whether accepted number is prime or not.
ans:refer slip no:6 q1
slip no:17
q1.design a html form to accept a string.write php function to reverse a string.
ans:refer slip no.7 q1
q2. Declare array. Reverse the order of elements, making the first element last and last
element first and similarly rearranging other array elements.[Hint : array_reverse()]
ans:refer slip no.7 q2
slip no:18
q.1design a htnl form to accept a string.write a php function that checks whether a passed string is a palindrome or n
ans:refer slip no:8 q1
slip no:19
q1. Write a PHP script to print following floyd’s triangle.
A
BC
DEF
GHIJ
ans: <?php
$char = 'A';
for ($i = 0; $i < 5; $i++) {
for ($j = 0; $j < $i; $j++) {
echo $char, "\t";
$char++;
}
echo "<br>";
}
?>
q2.Write a menu driven program to perform the following stack related operations.
c) Insert an element in stack.
d) Delete an element from stack.[Hint: array_push(), array_pop()] -->
ans: <html>
<body>
<form action="slip19_2.php" method="post">
1.Insert an element in stack <br>
<input type="number" name="num"> <br>
2.Delete an element from stack <br>
<input type="text" name="ch" id=""> <br>
<input type="submit" name="" id="">
</form>
</body>
</html>
<?php
$ch = $_POST['ch'];
$stack = array();
switch ($ch) {
case 1:
$element = $_POST['num'];
array_push($stack, $element);
echo "Element inserted into the queue: $element\n";
break;
case 2:
$deletedElement = array_pop($stack);
echo "Element deleted from the stack: $deletedElement\n";
break;
default:
echo "invalid input";
}
?>
slip no:20
q1.write a php code to display source code of a webpage.
ans:refer slip no:10 q1
q2. Q2. Write a menu driven program to perform the following queue related operations
d) Insert an element in queue
e) Delete an element from queue
f) Display the contents of queue
ans: refer slip no:10 q2