a) Write any 2 features of PHP & HTML.
● PHP:
1. P HP is a server-side scripting language that allows for dynamic content
generation.
2. PHP can easily interact with databases like MySQL and PostgreSQL.
● HTML:
1. HTML is a markup language used to structure web pages with elements
like headings, paragraphs, links, etc.
2. It supports embedding multimedia elements such as images, audio,
and video.
b) Write the output of the following PHP Script:
hp
p
Copy code
<?php
$age = array("Anna"=>"45", "Julie"=>"38", "Benne"=>"53");
usort($age);
print_r($age);
?>
● T
he script will throw awarning/errorbecauseusort()is designed for indexed
arrays, not associative arrays.
c) Write the output of the following script:
hp
p
Copy code
<?php
$a='PHP';
$b='$a interpolation ';
echo $b;
?>
● T
he output will be:'$a interpolation'. Single quotes prevent variable
interpolation in PHP.
d) Write the output of the following PHP Script:
hp
p
Copy code
$str='abc,pqr,lmn,xyz';
$p = explode(',', $str, 3);
print_r($p);
● The output will be:
hp
p
Copy code
Array
(
[0] => abc
[1] => pqr
[2] => lmn,xyz
)
heexplode()function splits the string into 3 parts, and the last part includes the rest
T
of the string after the third split.
e) What is the output of the following?
hp
p
Copy code
<?php
$p = array(1,2,3,4,5);
$q = array(1,3,5,7,9);
$s = array_diff($p, $q);
print_r($s);
?>
● The output will be:
hp
p
Copy code
Array
(
[1] => 2
[3] => 4
)
hearray_diff()function returns the values from array $p that are not present in
T
array $q.
a) Differentiate between single quoted string and double quoted string.
● S ingle quoted stringsdo not process variables or special characters (except
backslashes and single quotes themselves).
● Double quoted stringsallow variable interpolation and handle escape
sequences like\n(new line) and\t(tab).
b) How is External CSS used?
● E
xternal CSS is linked to an HTML document using the<link>tag placed
within the<head>section. Thehrefattribute specifies the path to the CSS file,
and therelattribute defines the relation asstylesheet.
c) Write any two functions of decomposing a string with a suitable example.
1. explode(): Splits a string into an array based on a delimiter.
○ Example:explode(',', 'apple,banana,grape')will result in['apple',
'banana', 'grape'].
2. str_split(): Splits a string into an array, either character-by-character or by a
given length.
○ Example:str_split('hello', 2)results in['he', 'll', 'o'].
d) How to find the position of the first occurrence of a substring in a string?
● U
se thestrpos()function to find the position of the first occurrence of a
substring. For example,strpos('hello world', 'world')will return6.
e) What is the purpose of array_splice() function?
● T
hearray_splice()function removes a portion of an array and can replace it
with new elements. It's also used to remove elements without replacement.
Explain List in HTML.
● L
ists in HTML are used to present items in a structured format. There are two
main types of lists:
1. Ordered List (<ol>): Displays items in a numbered sequence.
2. Unordered List (<ul>): Displays items with bullet points.
What is Casting of operators?
● C
asting operators in PHP are used to convert a variable from one data type to
another. For example,(int)converts a value to an integer, and(string)converts
it to a string.
Find the Output:
hp
p
Copy code
$subjects = array('physics', 'chem', 'math', 'bio', 'cs', 'drama');
$rl = array_splice($subjects, 2, 3);
print_r($subjects);
● The output will be:
hp
p
Copy code
Array
(
[0] => physics
[1] => chem
[2] => drama
)
array_splice()removedmath,bio, andcs, leavingphysics,chem, anddrama.
Explain the following functions:
● v ar_dump(): Displays structured information about one or more variables,
including its type and value.
● trim(): Removes whitespace or other predefined characters from the
beginning and end of a string.
Define the types of web pages.
1. S tatic Web Pages: Pages that remain the same for every user. They do not
change based on user interaction.
2. Dynamic Web Pages: Pages that change content dynamically based on user
interaction or server-side data.
a) Find the Output:
hp
p
Copy code
$city = 'pune';
$string = 'I like $city very much!';
echo $string;
● T
he output will be:I like $city very much!because single quotes prevent
variable interpolation.
b) Find the Output:
hp
p
Copy code
$file = fopen("sample.txt", "w");
echo fwrite($file, "Hello! How are you Rahul?");
fclose($file);
● The output will be27, which is the number of bytes written to the file.
c) Find output of the following code:
hp
p
Copy code
a = "1E3 points of light" + 1;
$
var_dump($a);
● T
he output will be:float(1001). The string"1E3"is interpreted as1000in
scientific notation, and adding1results in1001.
d) What is the use of var_dump() function?
● T
hevar_dump()function outputs the detailed information of a variable, such
as its data type and value, including arrays and objects.
e) What is the use of mail() function? Give syntax of it.
● T
hemail()function is used to send emails in PHP. Syntax:mail(to, subject,
message, headers).