[go: up one dir, main page]

0% found this document useful (0 votes)
26 views8 pages

Server Side Scripting Questions and Answers

Chapter 4 discusses elementary server-side scripting using PHP, covering topics such as XHTML, differences between HTML and XHTML, PHP advantages, variable declaration rules, data types, operators, conditional statements, and loops. It explains the syntax and usage of various PHP constructs including if-else statements, switch statements, and different types of loops. The chapter also includes true/false questions to reinforce understanding of the material.

Uploaded by

shiptaarshita
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views8 pages

Server Side Scripting Questions and Answers

Chapter 4 discusses elementary server-side scripting using PHP, covering topics such as XHTML, differences between HTML and XHTML, PHP advantages, variable declaration rules, data types, operators, conditional statements, and loops. It explains the syntax and usage of various PHP constructs including if-else statements, switch statements, and different types of loops. The chapter also includes true/false questions to reinforce understanding of the material.

Uploaded by

shiptaarshita
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Chapter-4

Elementary server Side Scripting through PHP

Q.1 What do you mean by XHTML?

Answer: XHTML stands for Extensible Hyper Text Markup Language. XHTML
was developed by World Wide Web Consortium to help the web developers
make the transition from HTML to XML. XHTML documents need to be well
formed, the website will be compatible with preset and future web browsers
and rendered more accurately. It also makes website easier to maintain,
convert and format in the long run. XHTML syntax is very similar to HTML
syntax and almost all the HTML elements are valid in XHTML as well.

Q.2 What is the difference between HTML and XHTML.


Answer:
Sr. No. HTML XHTML
1. Hypertext Markup Language Extensible Hypertext
Markup Language
2. HTML is not case sensitive EHTML is case Sensitive
3. For HTML, internet media type is For HHTML, it is
text/html application /xhtml+xml.
4. HTML is less expressive XHTML is more
expressive as compared
to HTML.
5. HTML is an application of SGML XHTML is an application
of XML.
6. HTML has document file format XHTML has markup
language as type format

Q.3 What do you mean by PHP? What are advantages of PHP?

Answer: PHP stands for Hypertext Pre-processor, that earlier stood for
personal Home Pages. PHP is a server side scripting language that is used to
develop static websites or Dynamic websites or web application. PHP scripts
can only be interpreted on a server that has PHP installed. The client
computers accessing the PHP scripts require a web browser only. A PHP file
contains PHP tags and ends with the extension “.php”.

Advantages:

1. Easy and Simple to Learn. PHP is considered one of the easiest scripting
languages.
2. Open source software. PHP is open source software and available free of
cost.
3. Extremely Flexible. PHP is highly flexible whether it is during an ongoing
project or after completing the project.
4. It can run on many operating systems. PHP runs on a variety of
operating system like windows, LINUX, MAC etc.
5. It is secure. The user cannot see the PHP code.
6. Easy Integration and Compatibility.
7. Efficient Performance.
8. Cost-Efficient.

Q.4 What is variable? What are the rules for declaring a variable?
Answer: Variables are used for storing values such as numeric values,
characters, character strings, or memory addresses so that they can be used in
any part of the program. A variable can have a short name (like x and y) or a
more descriptive name (age, carname, total_volume).
Rules for PHP variables:
1. A variable starts with the $ sign, followed by the name of the variable
2. A variable name must start with a letter or the underscore character
3. A variable name cannot start with a number
4. A variable name can only contain alpha-numeric characters and
underscores (A-z, 0-9, and _ )
5. Variable names are case-sensitive ($age and $AGE are two different
variables)
Q.5 What do you mean by Data types? What are various data types
used in PHP?
Answer: A data type, in programming, is a classification that specifies which
type of value a variable has and what type of mathematical, relational or logical
operations can be applied to it without causing an error. Values stored in
variable or a constant are stored as a specific type of data. PHP provides
different data types to hold different types of values.
PHP supports the following data types:
1. String:- A string is a sequence of characters, like "Hello world!".
2. Integer:- An integer data type is a non-decimal number between -
2,147,483,648 and 2,147,483,647 E.g. 40,73,-99
3. Float (floating point numbers - also called double):- A float (floating
point number) is a number with a decimal point or a number in
exponential form E.g. 1.56 , 40.7
4. Boolean:- A Boolean represents two possible states: TRUE or FALSE.
5. Array:- An array stores multiple values in one single variable.
6. Object:- An object is a data type which stores data and information on
how to process that data.
7. NULL:- Null is a special data type which can have only one value: NULL

Q.6 Define operator. Explain Arithmetic operators with examples.

Answer: Operators are symbols that tell the PHP processor to perform certain
actions. For example, the addition ( + ) symbol is an operator that tells PHP to
add two variables or values, while the greater than ( > ) symbol is an operator
that tells PHP to compare two values. Operators are used to perform operations
on variables and values.
PHP divides the operators in the following groups:
1. Arithmetic operators
2. Assignment operators
3. Comparison operators
4. Increment/Decrement operators
5. Logical operators
6. String operators
Arithmetic operators are used with numeric values to perform common
arithmetical operations, such as addition, subtraction, multiplication etc.
There are five basic arithmetic operators.
1. + (addition)

2. - (subtraction)

3. * (multiplication)

4. / (division)

5. % (modulus)
The operators are summarized in the following table.
Let $x=5 and $ y = 3

Operator Name Example Result


+ Addition $x + $y Sum of $x and $y. 8
- Subtraction $x - $y Difference of $x and $y. 2
* Multiplication $x * $y Product of $x and $y. 15
/ Division $x / $y Quotient of $x and $y 1
% Modulus Modulus$x % $y$x % $y$x
Remainder
% $y of $x
Remainder
divided
Remainder
byof$y.
$x 2of $x
divided
divided
by $y.by $y.

Q. 7 What do you mean by Comparison Operators in PHP.


Answer: The PHP comparison operators are used to compare two values
(number or string):
Operator Name Example Result
== Equal $x == $y Returns true if $x is equal to $y
!= Not equal $x != $y Returns true if $x is not equal to
$y
<> Not equal $x <> $y Returns true if $x is not equal to
$y
> Greater than $x > $y Returns true if $x is greater
than $y
< Less than $x < $y Returns true if $x is less than $y
>= Greater than or $x >= $y Returns true if $x is greater
equal to than or equal to $y
<= Less than or $x <= $y Returns true if $x is less than or
equal to equal to $y

Q.8 Why conditional statements are used in PHP? Explain.


Answer: Conditional statements enables the programmer to make decisions
based on text condition i.e.. Conditional statements are used to perform
different actions based on different conditions. The various conditional
statements are:
If statement
If else statement
It else if statement
Switch statement

Q. 9 Explain if-else statement.

The if… else statement executes some code if a condition is true and another
code if that condition is false.
Syntax:
if (condition)
{
If Block Statements to be executed if condition is true;
}
else
{
Else Block Statements to be executed if condition is false;
}
In if else statement the condition is evaluate first if it is true statements in the
if block will be executed and if condition is false the statements in the else will
be executed.
Example:
$x=6;
if($x>5)
{
echo “We are in the if block”;
}
Else
{
echo “We are in the else block”;
}
As 6>5 so condition is true so if block will execute and output will be We are in
the if block.
Q. 10 Explain if-else-if statement.
Answer: In the if-else-if statement we can use more than one if statements. It
is also called nested if statement.
Syntax:
if (condition)

{
Statements to be executed if condition is true;
}
elseif(condition)
{
Statements to be executed if condition in second if is
true;
}
else
{
Statements to be executed if condition is false;
}

In the if-else-if statement condition in the first if will be checked if it is true the
statements in the first if block will be executed. If condition is false then the
condition in the second if will be checked if it is true the statements in second
if block will be executed otherwise statements in the else block will be
executed.

Q.11 What is the purpose of loops. What are the various types of
loops used in PHP?

Loops are used to execute the same block of code again and again, as long as a
certain condition is met. The basic idea behind a loop is to automate the
repetitive tasks within a program to save the time and effort.
PHP supports four different types of loops.

1. Do-while Loop
2. While Loop
3. For Loop
4. Foreach Loop

Q.12 Explain do-while loop in PHP.

Answer: The do-while loop will always execute the block of code once, it will
then check the condition, and repeat the loop while the specified condition is
true.
Syntax
do
{
Statements to be executed;
} while (condition);
In Do-while loop statements in the do-while block will be executed first then
condition is checked if it is true will execute again. This process will remain
continue until condition remain true. The control will come out of the do-while
loop when condition become false.
Example
The example below displays the numbers from 1 to 5:
<?php
$x = 1;
do
{
echo "The number is: $x <br>";
$x++;
}
while ($x <= 5);
?>
Output:
1
2
3
4
5

Q.13 Explain while loop in PHP.


Answer: The while loop executes a block of code as long as the specified
condition remain true.
Syntax
while (condition)
{
Statements to be executed;
}
In while loop condition is checked if it is true statements in the while block will
be executed again condition is checked again if it is true statements in the
body will be executed. This process will be continued until condition become
false.
Q. 14 Explain switch statement in PHP.
Answer: The switch-case statement is an alternative to the if-else-if
statement, which does almost the same thing. The switch-case statement tests
a variable against a series of values until it finds a match, and then executes
the block of code corresponding to that match.
Syntax:
$n=3;
switch ($n)
{
case label1:
Statements to be executed if n=label1;
break;
case label2:
Statements to be executed if n=label2;
break;
case label3:
Statements to be executed if n=label3;
break;
...
default:
Statements to be executed if n is different from all labels;
}

True/ False
1. A variable name cannot start with a number.
2. In PHP echo statement is often is used to input data to the
computer.
3. An integer can be either positive or negative.
4. An array stores multiple values in one single variable.
5. Constants are automatically global across the entire script.
6. Comparison operators have only true or false value.
7. Switch statement is used to select one of many blocks of code
to be executed.
8. Do-while loop do not execute the statement while condition is
false.

Answer: 1. True 2. False 3. True 4. True 5. True


6. True 7. True 8. False

You might also like