WebTech Question Paper-2
WebTech Question Paper-2
1 Marks Questions
a) Which tag is used to set the text in Superscript format?
The <sup> tag is used to set the text in superscript format in HTML.
The <style> tag is used in HTML to define internal styles for an HTML document. It
contains CSS (Cascading Style Sheets) code to specify the appearance and layout
of elements on the page.
<?php
mkdir("new_directory");
?>
Question Paper-2 1
g) What is a DSN?
DSN stands for Data Source Name. It is a string that specifies the connection
information and parameters needed to connect to a database.
<?php
$object = new stdClass();
$object->name = "John";
$array = get_object_vars($object);
print_r($array);
?>
2 Marks Questions
Question Paper-2 2
Variables and escape sequences are expanded.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, init
<link rel="stylesheet" href="styles.css">
<title>External CSS Example</title>
</head>
<body>
<!-- Content of the HTML document -->
</body>
</html>
explode() Function:
<?php
$string = "apple,orange,banana";
$fruits = explode(",", $string);
print_r($fruits);
?>
str_split() Function:
Question Paper-2 3
<?php
$string = "Hello";
$characters = str_split($string);
print_r($characters);
?>
d) How to find out the position of the first occurrence of a substring in a string?
The strpos() function is used to find the position of the first occurrence of a substring
in a string.
<?php
$string = "Hello, World!";
$position = strpos($string, "World");
echo "Position of 'World': $position";
?>
<?php
$colors = array("red", "green", "blue");
$removed = array_splice($colors, 1, 1, "yellow");
print_r($colors); // Output: Array ( [0] => red [1] => yell
print_r($removed); // Output: Array ( [0] => green )
?>
4 Marks Questions
a) Discuss the Scope of a Variable in PHP with an example
Question Paper-2 4
The scope of a variable refers to the context in which it is defined and can be
accessed. PHP has three main variable scopes: local, global, and static.
Example:
<?php
// Global scope variable
$globalVar = "I am global";
function exampleFunction() {
// Local scope variable
$localVar = "I am local";
echo $localVar; // Accessible only within the function
exampleFunction();
prepare() Method:
<?php
$stmt = $conn->prepare("INSERT INTO employees (name, s
Question Paper-2 5
$stmt->bind_param("si", $name, $salary);
$name = "John";
$salary = 50000;
$stmt->execute();
?>
execute() Method:
<?php
$stmt = $conn->prepare("SELECT name, salary FROM emplo
$stmt->bind_param("i", $employeeId);
$employeeId = 1;
$stmt->execute();
$stmt->bind_result($name, $salary);
$stmt->fetch();
echo "Name: $name, Salary: $salary";
?>
c) Explain the functions used for reading and writing characters in files
Functions for Reading Characters:
<?php
$file = fopen("example.txt", "r");
$content = fread($file, filesize("example.txt"));
fclose($file);
echo $content;
?>
<?php
$file = fopen("example.txt", "r");
Question Paper-2 6
while (!feof($file)) {
$line = fgets($file);
echo $line;
}
fclose($file);
?>
<?php
$file = fopen("example.txt", "w");
fwrite($file, "Hello, World!");
fclose($file);
?>
<?php
file_put_contents("example.txt", "Hello, World!");
?>
4 Marks Questions
a) Design HTML form that will accept user input of user name, Address, provide
buttons to submit the input as well as to refresh it.
HTML Form:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, init
<title>User Input Form</title>
</head>
<body>
Question Paper-2 7
<form action="process_form.php" method="post">
<label for="username">User Name:</label>
<input type="text" id="username" name="username" re
<label for="address">Address:</label>
<textarea id="address" name="address" rows="4" requ
b) Write PHP Script to accept an associative array and sort it in descending order.
Display the sorted array to the user.
<?php
// Accept associative array
$userInfo = array(
"username" => "JohnDoe",
"address" => "123 Main Street",
// Add more fields as needed
);
Question Paper-2 8
c) Accept directory name from the user. Write a PHP program to change the
current directory to the accepted directory name and count the number of files
and directories in it.
<?php
// Accept directory name from the user (assuming it's submi
$directoryName = $_POST['directory'];
Note: Ensure proper validation and security measures are implemented when
accepting user input, especially directory names, to prevent potential security
issues.
3 Marks Questions
a) Explain terms HTTP request and HTTP response.
HTTP Request:
An HTTP request is a message sent by a client to request a specific action from a
server. It consists of:
Request Line: Specifies the HTTP method (e.g., GET, POST) and the
resource (URL) being requested.
Question Paper-2 9
Headers: Additional information about the request (e.g., user-agent,
content-type).
Body: Data sent with the request, often used in POST requests.
HTTP Response:
Status Line: Indicates the status of the response (e.g., 200 OK, 404 Not
Found).
Example:
HTTP Request:
HTTP Response:
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 123
<html>
<!-- Response content -->
</html>
Question Paper-2 10
<?php
// Function that expects two parameters
function addNumbers($num1, $num2) {
return $num1 + $num2;
}
Explanation:
The addNumbers function expects two parameters ( $num1 and $num2 ), but when
calling it, only one parameter (5) is provided. This results in a missing parameter.
In this example, PHP will issue a warning or notice about the missing parameter,
and the result will be based on default values or null if not specified.
Question Paper-2 11