Tribhuwan University

Institute of Science and Technology

2080

Bachelor Level / Third Year / Fifth Semester / Science

Bachelors in Information Technology (BIT301)

(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.

Section A

Long Answers Questions

Attempt any TWO questions.
[2*10=20]
1.
How can you embed PHP code in web pages? Write a PHP program to illustrate the concepts of continue and break statements.[10]

How to Embed PHP Code in Web Pages & Continue/Break Statements


Part A: Embedding PHP Code in Web Pages

PHP code is embedded within HTML pages using special PHP tags that tell the web server to interpret the enclosed code as PHP.

There are four ways to embed PHP code in web pages:

a) Standard Tags (Recommended):

<?php
    echo "Hello World";
?>

b) Short Open Tags:

<?
    echo "Hello World";
?>
  • Requires short_open_tag = On in php.ini

c) ASP-Style Tags:

<%
    echo "Hello World";
%>
  • Requires asp_tags = On in php.ini

d) Script Tags:

<script language="php">
    echo "Hello World";
</script>

Key Points:

  • PHP code can be placed anywhere within an HTML document
  • The standard tag <?php ?> is the most portable and universally supported method
  • PHP statements are terminated with a semicolon (;)
  • The web server processes PHP code and sends only HTML output to the browser

Part B: PHP Program Illustrating Continue and Break Statements

break terminates the entire loop immediately, while continue skips the current iteration and moves to the next iteration.

Program:

<?php
    echo "<h2>Demonstration of Break Statement</h2>";
    echo "Printing numbers 1 to 10, but breaking at 5:<br>";
    
    for ($i = 1; $i <= 10; $i++) {
        if ($i == 5) {
            break;  // Loop terminates completely when i equals 5
        }
        echo $i . " ";
    }
    
    echo "<br>Loop ended due to break.";

    echo "<h2>Demonstration of Continue Statement</h2>";
    echo "Printing numbers 1 to 10, but skipping 5:<br>";
    
    for ($i = 1; $i <= 10; $i++) {
        if ($i == 5) {
            continue;  // Skips iteration when i equals 5
        }
        echo $i . " ";
    }
    
    echo "<br>Loop completed, only 5 was skipped.";
?>

Output:

Demonstration of Break Statement
Printing numbers 1 to 10, but breaking at 5:
1 2 3 4
Loop ended due to break.

Demonstration of Continue Statement
Printing numbers 1 to 10, but skipping 5:
1 2 3 4 6 7 8 9 10
Loop completed, only 5 was skipped.

Difference Between Break and Continue

Feature break continue
Action Exits the entire loop Skips current iteration only
Execution after Code after loop executes Next iteration begins
Use case Stop searching after match found Skip unwanted values

Conclusion: PHP is embedded in HTML using <?php ?> tags. The break statement completely terminates loop execution, while continue only skips the current iteration and proceeds with the next one. Both are essential for controlling loop flow in PHP programs.

2.
Describe variables and missing parameters with examples. Write a PHP program to implement functions containing parameters by reference.[10]
3.
How can you create a database connection? Create a PHP form that includes text field, password field, radio button elements. Now write a function to insert the data in the fields into a database table.[10]
Section B

Short Answers Questions

Attempt any Eight questions.
[8*5=40]
4.
How is the approximate equality of two strings done in PHP? Write a program to demonstrate it. [5]
5.
What is a cookie? Write PHP program to create cookie. [5]
6.
Define error reporting and error suppression with examples. [5]
7.
Write a PHP program to write on a file. [5]
8.
Write a PHP program to illustrate the use of exception handling. [5]
9.
Differentiate anonymous function from variable function. [5]
10.
Write a PHP program to access properties and methods of a class. [5]
11.
How can you remove and insert elements in an array? Explain by writing a PHP program using array_splice() for inserting and removing elements in an array. [5]
12.
Write a PHP program to demonstrate the concept of inheritance. [5]