JNTU

JNTU B.Tech III Year WEB TECHNOLOGIES Previous Question Paper (September - 2021 - R18)

B.Tech | III Year | I Semester | R18 | September - 2021

Answer PaperPaper Code: 155DNMaximum Marks: 75Time: 3 hours

Answer any five questions

All questions carry equal marks

Main

115 marks
a

Discuss about various functions used in PHP with suitable coding examples.

8 marks

Answer

JNTU

WEB TECHNOLOGIES

B.Tech, CSE, R18, III-I

Exam Month-Year: May-2024, Max Marks: 75, Time: 3 Hours

Instructions: Answer all questions. Each question carries equal marks.

Discuss about various functions used in PHP with suitable coding examples.

Marks: 8

  • PHP offers a vast collection of built-in functions that simplify common programming tasks. These functions can be broadly categorized based on their purpose.
  • String Functions: Manipulate string data. Examples include:
    • strlen(): Returns the length of a string.
    • <?php
      $text = "Hello World";
      echo strlen($text); // Output: 11
      ?>
    • str_replace(): Replaces all occurrences of a substring with another substring.
    • <?php
      $original = "The quick brown fox";
      $new = str_replace("brown", "red", $original);
      echo $new; // Output: The quick red fox
      ?>
    • substr(): Extracts a part of a string.
    • <?php
      $string = "Hello";
      echo substr($string, 1, 3); // Output: ell
      ?>
  • Array Functions: Work with arrays. Examples include:
    • count(): Returns the number of elements in an array.
    • <?php
      $fruits = array("apple", "banana", "cherry");
      echo count($fruits); // Output: 3
      ?>
    • implode(): Joins array elements into a string.
    • <?php
      $array = array("Hello", "World");
      $text = implode(" ", $array);
      echo $text; // Output: Hello World
      ?>
    • sort(): Sorts an array in ascending order.
    • <?php
      $numbers = array(4, 6, 2, 22);
      sort($numbers);
      print_r($numbers); // Output: Array ( [0] => 2 [1] => 4 [2] => 6 [3] => 22 )
      ?>
  • Mathematical Functions: Perform mathematical operations. Examples include:
    • abs(): Returns the absolute value of a number.
    • <?php
      echo abs(-4.7); // Output: 4.7
      ?>
    • sqrt(): Returns the square root of a number.
    • <?php
      echo sqrt(9);
      ?>
    • round(): Rounds a floating-point number.
    • <?php
      echo round(3.14159, 2); // Output: 3.14
      ?>
  • Date and Time Functions: Handle dates and times. Examples include:
    • date(): Formats a local date and time.
    • <?php
      echo date("Y-m-d H:i:s"); // Output: e.g., 2024-05-15 10:30:00
      ?>
    • time(): Returns the current Unix timestamp.
    • <?php
      echo time(); // Output: current Unix timestamp
      ?>
  • File Handling Functions: Interact with the file system. Examples include:
    • fopen(): Opens a file or URL.
    • fclose(): Closes an open file pointer.
    • fread(): Reads from an open file.
    • <?php
      $file = fopen("test.txt", "r");
      if ($file) {
          $content = fread($file, filesize("test.txt"));
          echo $content;
          fclose($file);
      }
      ?>
  • Database Functions (e.g., MySQLi): Interact with databases. Examples include:
    • mysqli_connect(): Establishes a new connection to a MySQL database.
    • mysqli_query(): Performs a query on the database.
    • mysqli_fetch_assoc(): Fetches a result row as an associative array.
    • <?php
      $conn = mysqli_connect("localhost", "username", "password", "database");
      if (!$conn) {
          die("Connection failed: " . mysqli_connect_error());
      }
      $sql = "SELECT id, name FROM users";
      $result = mysqli_query($conn, $sql);
      if (mysqli_num_rows($result) > 0) {
          while($row = mysqli_fetch_assoc($result)) {
              echo "id: " . $row["id"]. " - Name: " . $row["name"]. "<br>";
          }
      } else {
          echo "0 results";
      }
      mysqli_close($conn);
      ?>
  • These are just a few examples, and PHP provides many more functions for various tasks like form handling, session management, object-oriented programming, and more. Understanding and utilizing these functions is crucial for efficient web development in PHP.
b

Write a PHP script for searching for a web page.

7 marks

Answer

JNTU

WEB TECHNOLOGIES

B.Tech, CSE, R18, III-I

Exam Month-Year: May-2024, Max Marks: 75, Time: 3 Hours

Instructions: Answer all questions. Each question carries equal marks.

Write a PHP script for searching for a web page.

Marks: 7

Searching for a web page typically involves fetching the content of a given URL and then performing a search within that content. PHP can achieve this using functions like file_get_contents() or cURL to retrieve the page content, and then string manipulation functions to find the desired keyword.

Here's a PHP script that demonstrates how to search for a keyword on a specific web page:

<?php

// Function to search for a keyword on a given URL
function searchWebPage($url, $keyword) {
    // Use file_get_contents to fetch the HTML content of the URL
    // @ suppresses warnings if the URL is not accessible
    $htmlContent = @file_get_contents($url);

    if ($htmlContent === FALSE) {
        return "<p style='color:red'>Error: Could not retrieve content from URL: " . htmlspecialchars($url) . "</p>";
    }

    // Use stripos to find the position of the keyword (case-insensitive)
    // stripos returns the position of the first occurrence of a substring in a string, case-insensitive.
    // It returns FALSE if the keyword is not found.
    $position = stripos($htmlContent, $keyword);

    if ($position !== FALSE) {
        // Keyword found
        return "<p style='color:green'>Keyword '<b>" . htmlspecialchars($keyword) . "</b>' found on page '<b>" . htmlspecialchars($url) . "</b>' at position " . ($position + 1) . ".</p>";
    } else {
        // Keyword not found
        return "<p style='color:orange'>Keyword '<b>" . htmlspecialchars($keyword) . "</b>' not found on page '<b>" . htmlspecialchars($url) . "</b>'.</p>";
    }
}

// --- Example Usage ---

// Define the URL to search and the keyword
$targetUrl = "https://www.example.com"; // Replace with the actual URL
$searchKeyword = "Example"; // Replace with the keyword you want to search for

// Call the function and display the result
echo searchWebPage($targetUrl, $searchKeyword);

// Another example with a different keyword
$searchKeyword2 = "NonExistentKeyword";
echo searchWebPage($targetUrl, $searchKeyword2);

// Example with a potentially problematic URL (for testing error handling)
$badUrl = "http://thisisnotavalidurl12345.com";
$keywordForBadUrl = "test";
echo searchWebPage($badUrl, $keywordForBadUrl);

?>

Explanation:

  • searchWebPage($url, $keyword) function: This function encapsulates the logic for searching. It takes the URL and the keyword as parameters.
  • @file_get_contents($url): This is the core function used to fetch the entire content of the web page into a string. The '@' symbol is used to suppress any potential warnings or errors if the URL is invalid or inaccessible, allowing us to handle errors gracefully.
  • Error Handling: The script checks if file_get_contents() returned FALSE, which indicates a failure to retrieve the page content. If an error occurs, an informative message is returned.
  • stripos($htmlContent, $keyword): This function searches for the first occurrence of the $keyword within the $htmlContent string. It is case-insensitive, meaning it will find "Example", "example", or "EXAMPLE". It returns the starting position (index) of the keyword if found, or FALSE if not found.
  • Result Output: Based on whether the keyword was found ($position !== FALSE), the script returns a user-friendly message indicating success or failure, along with the URL and the keyword.
  • htmlspecialchars(): This function is used to prevent cross-site scripting (XSS) vulnerabilities by converting special characters into HTML entities. It's good practice to use this when displaying user-provided or external data.

Note: This script performs a simple text search. For more complex web scraping or searching (e.g., searching within specific HTML tags, handling JavaScript-rendered content, or dealing with large amounts of data), more advanced techniques like using cURL with options for headers and timeouts, or employing dedicated scraping libraries, might be necessary.

215 marks
a

Summarize about various types of PHP interpreters.

7 marks

Answer

Sign in to view the complete answer paper.

b

Write a PHP script to add a user to Login table in MySql database.

8 marks

Answer

Sign in to view the complete answer paper.

315 marks
a

What is XML Schema? List the advantages of it over DTD.

7 marks

Answer

Sign in to view the complete answer paper.

b

Describe XML schema for designing a web page for product display.

8 marks

Answer

Sign in to view the complete answer paper.

415 marks
a

What is XML? List characteristic features of XML.

6 marks

Answer

Sign in to view the complete answer paper.

b

What are XML namespaces? Describe the XML namespace for any webpage.

9 marks

Answer

Sign in to view the complete answer paper.

515 marks
a

Explain the life cycle of servlet? Write a simple servlet program to read two parameters from form data.

8 marks

Answer

Sign in to view the complete answer paper.

b

Distinguish Generic servlet from HttpServlet.

7 marks

Answer

Sign in to view the complete answer paper.

615 marks
a

Write a servlet program to retrieve data from the Employee table which is existing in MySql database.

8 marks

Answer

Sign in to view the complete answer paper.

b

Explain the advantages of servlets over CGI scripts.

7 marks

Answer

Sign in to view the complete answer paper.

715 marks
a

What are the implicit objects available in JSP? List the advantages of JSP over Servlets?

8 marks

Answer

Sign in to view the complete answer paper.

b

Explain about page directive with an example JSP code.

7 marks

Answer

Sign in to view the complete answer paper.

815 marks
a

Explain about Document Object Model with suitable example.

8 marks

Answer

Sign in to view the complete answer paper.

b

Write a Java Script function to check whether given number is prime or not.

7 marks

Answer

Sign in to view the complete answer paper.

About this paper

This page contains the solved question paper with answers of WEB TECHNOLOGIES from JNTU for B.Tech CSE III Year I Semester, September - 2021, R18.

For the question paper without answers, switch to the Question Paper tab.

Other papers in WEB TECHNOLOGIES

Loading Question Papers

Fetching data from database...