WT 2mq
WT 2mq
● 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.
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.
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);
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.
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);
?>
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).
● 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.
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.
● 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.
● 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.
hp
p
Copy code
$subjects = array('physics', 'chem', 'math', 'bio', 'cs', 'drama');
$rl = array_splice($subjects, 2, 3);
print_r($subjects);
hp
p
Copy code
Array
(
[0] => physics
[1] => chem
[2] => drama
)
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.
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.
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.
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.
● T
hevar_dump()function outputs the detailed information of a variable, such
as its data type and value, including arrays and objects.
● T
hemail()function is used to send emails in PHP. Syntax:mail(to, subject,
message, headers).