WEB TECH PYQ - BCS Guruji

Ad

Friday, December 8, 2023

WEB TECH PYQ

 -Which tag is used to set the text in Superscript format?

The <sup> tag is used for superscript text in HTML.

 - Explain the use of <Style>
The <style> tag in HTML is used to define the style information for a document, including CSS (Cascading Style Sheets) properties. 

 -How to create a directory in PHP?

The mkdir() function is used to create a directory in PHP. 

- How External CSS is used?

External CSS is applied by linking an external stylesheet file to an HTML document using the <link> tag within the document's <head> section.

Example: <link rel="stylesheet" type="text/css" href="styles.css">


-Discuss the Scope of a Variable in PHP with an example

PHP has three variable scopes: local, global, and static.

CODE:-

$globalVar = "I am global";

function exampleFunction() {

    $localVar = "I am local";

    echo $localVar;  // Accessible only inside the function

    echo $GLOBALS['globalVar'];  // Accessing a global variable

}

exampleFunction();

echo $localVar;  // Will cause an error

 


-Design HTML form that will accept user input of user name, Address, provide buttons to submit the input as -wellas to refresh it.

<form action="process.php" method="post">

  <label for="username">Username:</label>

  <input type="text" id="username" name="username" required>

  <label for="address">Address:</label>

  <textarea id="address" name="address" required></textarea>

  <button type="submit">Submit</button>

  <button type="reset">Refresh</button>

</form>

-Write PHP Script to accept associative array and sort in descending

 order. Display sorted array to user.

$array = array("John" => 30, "Jane" => 25, "Doe" => 35);

arsort($array);

foreach($array as $key => $value) {

  echo "$key: $value<br>";

}


 -Explain terms HTTP request and HTTP response.

An HTTP request is a message sent by a client (usually a web browser) to request information from a server. It includes a method (like GET or POST) and a URL.

An HTTP response is a message sent by the server back to the client in response to an HTTP request. It includes information such as status codes, headers, and the requested data.

 

-What is hyperlink?
A hyperlink is a clickable element on a web page, typically text or an image, that, when clicked, navigates the user to another location, which can be within the same document, to another web page, or to a different resource on the internet.

-  List the advantages of CSS

Separation of Concerns:

CSS separates the style and layout from the HTML structure, making the code more modular and easier to maintain.

Consistency:

CSS allows for consistent styling across multiple pages, ensuring a uniform look and feel throughout a website.

Page Load Speed:

External CSS files can be cached, reducing the load time for subsequent pages and improving overall performance.

Responsive Design:

CSS enables the creation of responsive designs that adapt to different screen sizes and devices.

- Which tag is used to set the text in superscript format?

 - State the purpose of pathinfo()

The pathinfo() function in PHP is used to extract information about a file path, such as the directory name, file name, extension, and filename without extension.

- List any two features of HTTP protocol.

Statelessness:

Each request from a client to a server is independent, and the server does not retain information about the client's state between requests.

Connectionless:

After a request is made and a response is sent, the connection between the client and server is closed. Subsequent requests require establishing a new connection.


- What is web server?
A web server is software that processes incoming network requests over HTTP or HTTPS protocols. It serves web content (HTML pages, images, CSS, etc.) to clients (web browsers) based on their requests.

 

 

 -Write any 2 features of PHP & HTML

PHP:

Server-Side Scripting:

PHP is a server-side scripting language, meaning it is executed on the server, and only the result is sent to the client. This allows for dynamic content generation.

Extensive Database Support:

PHP has robust support for interacting with databases, making it suitable for developing database-driven web applications.

HTML:

Markup Language:

HTML is a markup language used to structure content on the web. It provides a set of tags to define the structure of a web page.

Platform-Independent:

HTML is platform-independent, meaning it can be rendered and displayed consistently across different devices and browsers.

-Write the output of the following PHP Script

 <?php

 $ age = array("Anna"=>"45", "Julie"=>"38", "Benne"=>"53");

 usort($age);

 print_r($age);

 ?>

$age = array("Anna"=>"45", "Julie"=>"38", "Benne"=>"53");

usort($age);

print_r($age);
The output will be an error because usort() expects an array and usort($age) does not provide a comparison function.

 -Write the output of the following script?

 <?php

 $a='PHP';

 $b='$a interpolation ';

 echo $b;

 ?>

$a = 'PHP';

$b = '$a interpolation ';

echo $b;

The output will be: $a interpolation

 -Write the output of the following PHP Script.

 $str=' abc,pqr,lmn,xyz';

 $p=explode(',',$str,3);

 print_r($p);

$str = 'abc,pqr,lmn,xyz';

$p = explode(',', $str, 3);

print_r($p);

OUTPUT

Array

(

    [0] => abc

    [1] => pqr

    [2] => lmn,xyz

)

- What is the output of the following?

 <?php

 $p=array(1,2,3,4,5);

 $q=array(1,3,5,7,9);

 $s=array_diff($p,$q);

 print_r($s);

 ?>

$p = array(1, 2, 3, 4, 5);

$q = array(1, 3, 5, 7, 9);

$s = array_diff($p, $q);

print_r($s);

OUTPUT:
The output will be an array containing elements not present in both arrays:
Array
(
    [1] => 2
    [3] => 4
)

 -Design HTML form that will accept user input as first name, middle

 name and last name, address, contact number. Provide buttons to submit

 the input as well as to refresh form.

<form action="process.php" method="post">

  <label for="firstName">First Name:</label>

  <input type="text" id="firstName" name="firstName" required>


  <label for="middleName">Middle Name:</label>

  <input type="text" id="middleName" name="middleName">


  <label for="lastName">Last Name:</label>

  <input type="text" id="lastName" name="lastName" required>


  <label for="address">Address:</label>

  <textarea id="address" name="address" required></textarea>


  <label for="contactNumber">Contact Number:</label>

  <input type="tel" id="contactNumber" name="contactNumber" required>

  <button type="submit">Submit</button>

  <button type="reset">Refresh</button>

</form>




 


 


-Write a PHP script to read a file abc.txt where file contains character,

 B,C,T,G and space. Count occurrences of each character and write it

 to the abccount.txt file.

<?php

$filename = 'abc.txt';

$fileContents = file_get_contents($filename);

$charCount = array_count_values(str_split($fileContents));


// Write counts to a file

file_put_contents('abccount.txt', print_r($charCount, true));

?>





 

  -Define an Introspection
 Introspection is the ability of a program to examine the type or properties of an object during runtime. It allows a program to analyze its own structure or the structure of other objects.

 



- What is use of serialization?
Serialization is the process of converting complex data types (objects, arrays) into a format that can be easily stored or transmitted. In PHP, it's commonly used to store and retrieve object states, such as when working with sessions or caching.

 -What is a constructor?

A constructor in PHP is a special method that is automatically called when an object is created from a class. It is used to initialize object properties or perform any necessary setup when an object is instantiated

class MyClass {

    public function __construct() {

        echo "Constructor called.";

    }

}

 


- Write a Php program to accept associative array of five expenses

 (electricity bill, phone bill, petrol bill property tax, college fees) and their

 respective amount of’ two persons. print the total expenditure of each

 person.

<?php

$expenses = array(

    "electricity" => 120,

    "phone" => 50,

    "petrol" => 80,

    "property_tax" => 200,

    "college_fees" => 500

);


$person1 = array_sum($expenses) / 2;

$person2 = array_sum($expenses) / 2;


echo "Total expenditure for person 1: $" . $person1 . "<br>";

echo "Total expenditure for person 2: $" . $person2;

?>


 -What is inheritance? Explain with suitable example.

Inheritance is a feature in object-oriented programming where a class inherits properties and methods from another class. Example:

class Animal {

    public function sound() {

        echo "Animal makes a sound.";

    }

}


class Dog extends Animal {

    public function sound() {

        echo "Dog barks.";

    }

}


$dog = new Dog();

$dog->sound();  // Output: Dog barks.


- Write a Php script to read a file DNA. TXT where file contains character

 A, T, C G and space. Count occurrences of each character and write it

 to the DNACOUNT. TXT file.

<?php

$filename = 'DNA.txt';

$fileContents = file_get_contents($filename);

$charCount = array_count_values(str_split($fileContents));


// Write counts to a file

file_put_contents('DNACOUNT.txt', print_r($charCount, true));

?>



  -Explain the following statements with syntax and example

 While statement

 Switch statement

 While Statement:

Executes a block of code repeatedly as long as a specified condition is true.


$i = 1;

while ($i <= 5) {

    echo $i . " ";

    $i++;

}

// Output: 1 2 3 4 5


Switch Statement:

Selects one of many blocks of code to be executed.


$day = "Monday";

switch ($day) {

    case "Monday":

        echo "It's the start of the week.";

        break;

    // More cases...

}

 

 



 -What is class? Give syntax of class declaration in Php.

class MyClass {

    // Properties and methods go here

}

A class is a blueprint or a template for creating objects. It defines a set of properties (attributes) and methods (functions) that characterize an object of the class. 


 



 -How to move back to the first entry in a given directory

 while working with it ?

 the rewinddir function to move the directory handle back to the first entry.

 -Write the output of the following PHP script :

 function change( )

 { $cnt ++; }

 $cnt = 20;

 change( );

 echo $cnt;

<?php

function change() {

    $cnt++;

}

<?php

function change() {

    $cnt++;

}

$cnt = 20;

change();

echo $cnt;

?>

OUTPUT:

20

 

 -Write a PHP script to define class vector with size and integer

 elements. Define a construction to initialize the object. Accept

 vector elements and its size from user. Also write member

 functions to display its elements.

<?php

class Vector {

    public $size;

    public $elements;


    public function __construct($size) {

        $this->size = $size;

        // Initialize other properties as needed

    }


    public function setElements($elements) {

        $this->elements = $elements;

    }


    public function displayElements() {

        print_r($this->elements);

    }

}


// Usage example

$obj = new Vector(5);

$obj->setElements([1, 2, 3, 4, 5]);

$obj->displayElements();

?>






 


 


- Explain the concept of extends and implements with

 class.

extends: Used for inheritance, allowing a class to inherit properties and methods from another class.

class ParentClass {

    // Properties and methods

}


class ChildClass extends ParentClass {

    // Additional properties and methods

}

implements: Used to implement an interface, ensuring that the class contains the methods specified by the interface.

interface MyInterface {

    public function method1();

    public function method2();

}


class MyClass implements MyInterface {

    public function method1() {

        // Implementation

    }


    public function method2() {

        // Implementation

    }

}


- How do you define constant PI with value 3.142 in PHP ?

define('PI', 3.142);

echo PI;  // Output: 3.142

 -What is type casting ?

Type casting is the conversion of a variable from one data type to another.

Example: Converting a string to an integer.

$strNumber = "123";

$intNumber = (int)$strNumber;

echo $intNumber;  // Output: 123



 -How to create object in PHP ?

To create an object in PHP, you need to define a class and then instantiate it. Here's a simple example:

class MyClass {

    public $property;


    public function myMethod() {

        echo "Hello, I'm a method!";

    }

}

// Instantiate the class

$obj = new MyClass();

// Access the property and call the method

$obj->property = "Some value";

$obj->myMethod();

 -What will be output of the following :

 <?php

 ?>

 $a = “LK9”;

 $a++;

 Echo $a;

 -List any four web browser names.

Google Chrome

Mozilla Firefox

Microsoft Edge

Safari

 -List and explain (any three)the functions of PCRE.

preg_match(): Used to perform a regular expression match.

preg_replace(): Used to perform a regular expression search and replace.

preg_split(): Splits a string into an array using a regular expression.

- Write a PHP script to accept filename from the user and

 print total number of words.

 -Write a php script display the student details in table

 format.

<?php

$filename = readline("Enter the filename: ");

$fileContent = file_get_contents($filename);

$wordCount = str_word_count($fileContent);

echo "Total number of words: $wordCount";

?>


- Explain anonymous function concept in PHP.

Anonymous functions, also known as closures, allow the creation of functions without giving them a specific name. They can be assigned to variables and used as arguments in functions. Example:

$add = function($a, $b) {

    return $a + $b;

};

echo $add(3, 4); // Output: 7

- Write a short note on Interface
An interface in PHP is a contract specifying a set of methods that a class must implement. It allows for multiple inheritance and helps achieve abstraction. Classes implementing an interface must provide definitions for all the methods declared in the interface.

- State the features of PHP.

Open source.

Cross-platform (works on Windows, Linux, macOS).

Supports various databases.

Easy integration with HTML.

- State true or false :

 "Include "abc.php" can be written two times in a PHP

 script."
True. You can include a file multiple times in a PHP script.

- What is serialization ?
Serialization is the process of converting a data structure or object into a format that can be easily stored or transmitted, such as converting a PHP array into a string. This string can then be reversed back into the original data structure through deserialization.

-Write the output of the following PHP script :

 $white="show";

 $black=&$while;

 unset($white);

 print$black;

$white = "show";

$black = &$white;

unset($white);

print $black;

- Explain the PHP functions used to convert array into variables

 and vice versa.

To convert an array into variables: extract()

To convert variables into an array: compact()

- Write a PHP script to accept three strings str1, str2, str3

 from user. Search str2 in str1 and replace all occurrences

 of str2 by str3. Also display total number of occurrences.

<?php

$str1 = readline("Enter the main string: ");

$str2 = readline("Enter the string to search: ");

$str3 = readline("Enter the string to replace with: ");

// Perform the search and replace

$result = str_replace($str2, $str3, $str1, $count);

// Display the result and count

echo "Result: $result\n";

echo "Total occurrences replaced: $count\n";

?>

- How to call a constructor of a parent class from a child

 class ? Explain with suitable example.
Using  the parent::__construct()

class ParentClass {

    public function __construct() {

        echo "Parent constructor\n";

    }

}


class ChildClass extends ParentClass {

    public function __construct() {

        parent::__construct();

        echo "Child constructor\n";

    }

}


// Creating an object of the child class

$obj = new ChildClass();


 -Write the difference between break and continue statement

break: Exits the current loop or switch statement.

continue: Skips the rest of the current loop iteration and continues with the next one.

 - Write a PHP script to implement any two set operations.

 eg. union, intersection, difference.

<?php

$array1 = [1, 2, 3, 4, 5];

$array2 = [3, 4, 5, 6, 7];


// Union

$union = array_merge($array1, $array2);


// Intersection

$intersection = array_intersect($array1, $array2);


// Difference

$difference = array_diff($array1, $array2);


// Displaying results

echo "Union: " . implode(", ", $union) . "\n";

echo "Intersection: " . implode(", ", $intersection) . "\n";

echo "Difference: " . implode(", ", $difference) . "\n";

?>


- What is abstract class ? Write features of it.

An abstract class in PHP is a class that cannot be instantiated and may contain abstract methods. Features:

May have abstract methods with no implementation.

Can have both abstract and concrete methods.

Can't be instantiated; requires subclassing.

Provides a way to define a common interface for multiple classes.

-  Discuss PCRE preg_match( ) and preg_grep( ) with

 example.

preg_match(): Used to perform a regular expression match against a string.

$pattern = "/[0-9]+/";

$string = "The year is 2023.";

if (preg_match($pattern, $string, $matches)) {

    echo "Match found: " . $matches[0];

} else {

    echo "No match found.";

}


preg_grep(): Used to perform a regular expression search in an array.

$pattern = "/^John/";

$array = ["John Doe", "Jane Smith", "Doe John"];

$result = preg_grep($pattern, $array);

print_r($result);

- Give two examples of web browsers

- Abstract class must contain all abstract methods" Justify True/False. 
False. An abstract class may contain abstract methods, but it is not required to have only abstract methods. It can also have concrete (implemented) methods.

- Write a PHP program to acrept a string and print string divided into equal number of characters. (Consider spaces and enter character in calculation).

<?php

$string = readline("Enter a string: ");

$length = readline("Enter the length of each part: ");


// Using str_split to divide the string

$parts = str_split($string, $length);


// Displaying the result

echo "Result: " . implode(", ", $parts) . "\n";

?>


-Accept directory name from user. Write a PHP program to change norrent directory to acceptod directory name and count number of files and directories in it.

<?php

$directory = readline("Enter the directory path: ");

chdir($directory);


// Counting files and directories

$files = glob("*");

$fileCount = count($files);

$dirCount = count(array_filter($files, 'is_dir'));


echo "Number of files: $fileCount\n";

echo "Number of directories: $dirCount\n";

?>


-What in serialization? How is it used in PHPT

Serialization is the process of converting data into a format that can be easily stored or transmitted. In PHP, serialize() is used to convert data into a storable string, and unserialize() is used to reconstruct the original data from the serialized string.

Example:

$data = array("name" => "John", "age" => 25);

$serializedData = serialize($data);

// Store $serializedData in a file or transmit over the network

// Later, retrieve and unserialize the data

$originalData = unserialize($serializedData);

-Write a PHP program to sort array on marka (Array emtains names and marks)

<?php

$students = array(

    array("name" => "Alice", "marks" => 85),

    array("name" => "Bob", "marks" => 72),

    array("name" => "Charlie", "marks" => 95),

);


// Sorting the array based on marks

usort($students, function($a, $b) {

    return $b['marks'] - $a['marks'];

});


// Displaying the sorted array

print_r($students);

?>


- Write a short note en prepare and execute functions in databases

<?php

$students = array(

    array("name" => "Alice", "marks" => 85),

    array("name" => "Bob", "marks" => 72),

    array("name" => "Charlie", "marks" => 95),

);


// Sorting the array based on marks

usort($students, function($a, $b) {

    return $b['marks'] - $a['marks'];

});


// Displaying the sorted array

print_r($students);

?>

$pdo = new PDO("mysql:host=localhost;dbname=mydatabase", "username", "password");


// Prepare a statement

$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username");


// Bind parameters

$stmt->bindParam(':username', $username);


// Execute the statement

$stmt->execute();


// Fetch results

$result = $stmt->fetchAll(PDO::FETCH_ASSOC);


-Write a PHP program to create class college and derive class science from it with accept and print methods. -Accept. information from user assign it la class members and print 141

<?php

class College {

    protected $name;


    public function acceptInfo($name) {

        $this->name = $name;

    }


    public function printInfo() {

        echo "College Name: " . $this->name . "\n";

    }

}


class Science extends College {

    // Additional properties or methods specific to the Science class can be added here.

}


// Example usage

$scienceCollege = new Science();

$scienceCollege->acceptInfo("Science College");

$scienceCollege->printInfo();

?>


- Write a short note in directory manipulation.
Directory manipulation in PHP involves operations such as creating, reading, updating, and deleting directories. Functions like mkdir (create directory), rmdir (remove directory), opendir (open directory), and scandir (scan directory) are commonly used.

-Write role of web server in internet programming. 121
A web server handles requests from clients (usually browsers), processes them, and sends back responses. It interprets server-side scripts, manages resources, and communicates with databases. Common web servers include Apache, Nginx, and Microsoft IIS.

-Stats the advantages of PHP.

-What will be output of the following

<?php

$a= "K9;

$a++;

Echo $a;

?>

<?php

$a = "K9";

$a++;

echo $a;

?>


- What is interface?
An interface in PHP is a contract that defines a set of methods a class must implement. It provides a way to achieve abstraction and multiple inheritance in PHP.

-Keywords are ense sensitive in PHP Justify True or False
True. Keywords like if, else, class, etc., are case-sensitive in PHP. For example, IF or Else would not be recognized.

What is a scientific array? Explain with an example how it's different from an indexed array. Explain a French function.

An associative array in PHP is an array where each key is associated with a specific value. Unlike indexed arrays that use numeric indices, associative arrays use named keys.

Example:

$student = array(

    "name" => "John",

    "age" => 20,

    "grade" => "A"

);

In the example, "name," "age," and "grade" are keys associated with their respective values. A French function might be a function written in French, but it's not a standard term in PHP.






No comments:

Post a Comment