0% found this document useful (0 votes)
4 views

Web Sem5 (1)

Uploaded by

King Kong
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Web Sem5 (1)

Uploaded by

King Kong
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

A hyperlink is a link that allows users to navigate from one web

page to another or to different sections of the same page.


Define a web browser. A web browser is a software application
used to access and display content on the web, such as websites,
videos, and images. Examples include Chrome, Firefox, and Safari.
What is a web server? A web server is a computer system or
software that stores, processes, and delivers web pages to users
via a browser over the internet.
use of CSS selectors? CSS selectors are used to target HTML
elements and apply styles to them. For example, the selector p
applies styles to all <p> tags.
advantages of CSS. 1)Separation of content and design.
2)Faster loading pages due to smaller file sizes. 3)Easier
maintenance and updates. 4)Improved consistency across web
pages.
syntax to define a constant in PHP.
define("CONSTANT_NAME", "Value");
use of == and === operators
==: Compares two values for equality, ignoring type.
===: Compares both value and type for equality.
use of the foreach() The foreach() function is used to iterate over
each element in an array.
How to check if a given variable is an array or not?
Use the is_array() function. Example:
if (is_array($var)) {
echo "It is an array"; }
What is an associative array? An associative array is an array
that uses named keys instead of numeric indexes. Example:
$arr = ["name" => "John", "age" => 25];
What is the use of the array_flip() function?
The array_flip() function exchanges the keys and values in an array.
How to read a file in PHP?
Use the file_get_contents() or fread() functions to read a file.
function reads data CSV and puts data into an array?
getcsv() function.
State the purpose of the fileatime() function.
The fileatime() function returns the last access time of a file.
function to get a file name out of a file path?
basename() function.
unction repositions the file pointer to the beginning of the file?
rewind() function.
Which function enables you to print the contents of a file?
readfile() function.
How to delete a file in PHP? Use the unlink() function. Example:
unlink("filename.txt");
Give any two functions for random access of file data.
fseek(), ftell()
What is POP3? Post Office Protocol 3 (POP3) is a protocol used to
retrieve emails from a mail server to a local client.
What is the use of SMTP (Mail Transfer Agent)? SMTP is used to
send emails from a client to a mail server or between servers.
What is the use of Post Office Protocol 3? POP3 is used for
downloading and managing emails from a mail server to a local
client.
What is DSN? DSN (Data Source Name) is a data structure used
to describe a connection to a data source, such as a database.
List any two features of the HTTP protocol. Stateless: Each
request is independent of the previous one. Supports multiple
request methods like GET, POST, PUT, DELETE.
State the purpose of pathinfo(). The pathinfo() function returns
information about a file path, including directory name, basename,
extension, and filename.
What is a Lambda function?
A Lambda function, also known as an anonymous function, is a
function defined without a name. Example in PHP:
$sum = function($a, $b) {
return $a + $b;
};
advantages of PHP: Easy to Learn: PHP is beginner-friendly,
making it easier for new developers to start building websites and
web applications. Widely Used: Many websites, including popular
ones like Facebook and WordPress, use PHP, so there’s lots of
support and resources available. Open Source: PHP is free to use,
and you can easily find and use open-source tools and frameworks
that are built for PHP. Cross-Platform: PHP runs on various
operating systems like Windows, Linux, and macOS, allowing for
flexibility in development and deployment. Fast Performance: PHP
is efficient and can handle large amounts of data quickly, which
helps websites run smoothly.
Default parameters in programming are values that a function
automatically uses if no argument is provided when the function is
called.
Variable parameters refer to a feature in programming that allows
a function or method to accept a variable number of arguments.
This means you can pass different numbers of parameters to the
function without needing to define multiple versions of it.
types of strings: Single-Quoted Strings: Defined with single
quotes ('). They are treated literally, meaning special characters like
variables or escape sequences (except for \\ and \') are not
interpreted. For example: 'Hello, world!'.
Double-Quoted Strings: Defined with double quotes ("). They
allow for variable interpolation and escape sequences like \n for a
new line. For example: "Hello, $name!" where the $name will be
replaced with its value.
Explain the mail() function with syntax.

The mail() function sends an email in PHP.


Syntax:
mail(to, subject, message, headers);
Example:
mail("[email protected]", "Subject", "Message body", "From:
[email protected]");
Explain two syntax and proper examples of the foreach loop.
The foreach loop is used to iterate over arrays in PHP.
Syntax (Value only):

foreach ($array as $value) {


// Code to execute
}
Example:
$colors = ["red", "green", "blue"];
foreach ($colors as $color) {
echo $color . " "; }
Syntax (Key-Value pair):
foreach ($array as $key => $value) {
// Code to execute
}
Example:
$ages = ["Alice" => 25, "Bob" => 30];
foreach ($ages as $name => $age) {
echo "$name is $age years old. "; }
Explain types of strings in PHP.
PHP supports two types of strings:Single-quoted strings: Interpreted
literally. Variables and escape sequences are not parsed.Example:
$name = 'Alice';
echo 'Hello, $name'; // Output: Hello, $name
Double-quoted strings: Allow variable interpolation and escape
sequences. Example:
$name = 'Alice';
echo "Hello, $name"; // Output: Hello, Alice
How to get an array of keys and an array of values from an
associative array?
Getting keys: Use the array_keys() function. Example:
$arr = ["name" => "Alice", "age" => 25];
$keys = array_keys($arr); // Output: ["name", "age"]
Getting values: Use the array_values() function.
Example: $values = array_values($arr); // Output: ["Alice", 25]
What is the use of pg_fetch_row() and pg_fetch_array()?
pg_fetch_row(): Fetches a row from a PostgreSQL result as a
numeric array. Example:
$result = pg_query($conn, "SELECT * FROM users");
$row = pg_fetch_row($result);
pg_fetch_array(): Fetches a row as both a numeric and associative
array. Example:
$row = pg_fetch_array($result);
Explain the following functions with syntax and examples:
array_intersect(): Returns common elements from two arrays.
Example: $a1 = [1, 2, 3];
$a2 = [2, 3, 4];
print_r(array_intersect($a1, $a2)); // Output: [2, 3]
array_slice(): Extracts a portion of an array. Example:
$arr = [1, 2, 3, 4];
print_r(array_slice($arr, 1, 2)); // Output: [2, 3]
shuffle(): Randomizes array elements. Example:
$arr = [1, 2, 3];
shuffle($arr);
Explain how to send an email with PHP.
Use the mail() function to send an email.
Syntax:
mail(to, subject, message, headers);
Example:
$to = "[email protected]";
$subject = "Test Email";
$message = "This is a test email.";
$headers = "From: [email protected]";
mail($to, $subject, $message, $headers);
casting of operators Casting converts a variable from one data
type to another.Example:
$x = "10";
$int_x = (int)$x; // Converts string to integer
different types of arguments passed to functions with
examples.
Pass by Value: Default method. Original value is not modified.
Example:
function increment($num) {
$num++; }
Pass by Reference: Uses &. Modifies the original value.
Example:
function increment(&$num) {
$num++; }
Explain the advantages and disadvantages of the IMAP4
protocol.
Advantages: Emails remain on the server, accessible from multiple
devices. Supports folder management and search functionality.
Disadvantages: Requires internet to access emails.
More complex than POP3.
Explain lists in HTML.
Ordered List (<ol>): Displays items in a numbered format.
Example:
<ol>
<li>First</li>
<li>Second</li>
</ol>
Unordered List (<ul>): Displays items with bullets.
Example:
<ul>
<li>Apple</li>
<li>Banana</li>
</ul>

Define the types of web pages.Static Web Pages: Fixed content;


does not change dynamically. Dynamic Web Pages: Content
changes based on user interaction or database queries.
Explain the following functions:
var_dump(): Outputs the type and value of a variable.
Example:
var_dump(42); // Output: int(42)
trim(): Removes whitespace or specific characters from the
beginning and end of a string.
Example:
trim(" Hello "); // Output: "Hello"

Explain any two control statements with syntax and examples.


If-else:
if ($x > 0) {
echo "Positive";
} else {
echo "Negative";}
Switch-case:
switch ($day) {
case "Monday":
echo "Start of the week";
break;
default:
echo "Weekend";}
Explain the following functions with examples:
explode(): Splits a string into an array.
Example:
explode(",", "a,b,c"); // Output: ["a", "b", "c"]
implode(): Joins array elements into a string.
Example:
implode("-", ["a", "b", "c"]); // Output: "a-b-c"
Explain with example PEAR DB basics.
PEAR DB is a database abstraction layer for PHP. Example:
require_once "DB.php";
$dsn = "mysql://user:pass@localhost/dbname";
$db = DB::connect($dsn);
Associative array in PHP is a collection where each element has a
key-value pair. The keys can be strings or identifiers, which makes
it easier to access values using meaningful names rather than
numeric indices. An indexed array, on the other hand, uses numeric
indices (starting from 0) to store and access elements. It’s a simple
list of values without descriptive keys. Example:
Indexed Array: Elements are accessed by numeric indices.
$fruits = ["Apple", "Banana", "Cherry"];
echo $fruits[0]; // Outputs: Apple
Associative Array: Elements are accessed using named keys.
$person = ["name" => "John", "age" => 30];
echo $person['name']; // Outputs: John
Sort array with name and marks
<?php $students = array(
array("name" => "John", "marks" => 85),
array("name" => "Jane", "marks" => 92),);
usort($students, function($a, $b) {
return $a['marks'] - $b['marks']; });
echo "Sorted Students by Marks (Ascending):\n";
foreach ($students as $student) {
echo $student['name'] . " - " . $student['marks'] . "\n"; }?>
Features of PHP:
Server-Side Scripting: PHP runs on the server to generate
dynamic content like database-driven HTML.
Cross-Platform: PHP works on various operating systems
(Windows, macOS, Linux), ensuring flexibility.
Features of HTML:
Structure Web Pages: HTML defines webpage structure with tags
for content like headings, images, and forms.
Hyperlinking: HTML uses the <a> tag to create links for navigation
between pages or sections.

You might also like