Semester
Subject
Year
Tribhuwan University
2081
Bachelor Level / Third Year / Fifth Semester / Science
(Web Technology II)
Full Marks: 60
Pass Marks: 24
Time: 3 Hours
Candidates are required to give their answers in their own words as for as practicable.
The figures in the margin indicate full marks.
Long Answers Questions
Server side scripting is a technique where scripts are executed on the web server, and the resulting output (usually HTML) is sent to the client's browser.
How it works:
.php page)In PHP, a variable is declared using the dollar sign ($) followed by the variable name. PHP is a loosely typed language, so no data type declaration is needed.
Rules for declaring variables:
$ followed by the name (e.g., $name)$Age and $age are different)Example:
<?php
$name = "John"; // String variable
$age = 25; // Integer variable
$price = 99.5; // Float variable
$is_active = true; // Boolean variable
echo $name;
echo $age;
?>
Variable Scopes in PHP:
global keyword)The while loop executes a block of code as long as the specified condition is true. It is an entry-controlled loop (condition is checked before execution).
Syntax:
while (condition) {
// code to execute
}
Program: Print numbers 1 to 5 using while loop
<?php
$i = 1;
while ($i <= 5) {
echo "Number: " . $i . "<br>";
$i++;
}
?>
Output:
Number: 1
Number: 2
Number: 3
Number: 4
Number: 5
The do-while loop executes the block of code at least once, and then repeats as long as the condition is true. It is an exit-controlled loop (condition is checked after execution).
Syntax:
do {
// code to execute
} while (condition);
Program: Print numbers 1 to 5 using do-while loop
<?php
$i = 1;
do {
echo "Number: " . $i . "<br>";
$i++;
} while ($i <= 5);
?>
Output:
Number: 1
Number: 2
Number: 3
Number: 4
Number: 5
| Feature | While Loop | Do-While Loop |
|---|---|---|
| Type | Entry-controlled | Exit-controlled |
| Minimum execution | 0 times (if condition is false initially) | At least 1 time |
| Condition check | Before the loop body | After the loop body |
Conclusion: Server side scripting enables dynamic web content generation. PHP provides simple variable declaration using $ and supports both while (entry-controlled) and do-while (exit-controlled) loops for repetitive tasks.
Short Answers Questions