0% found this document useful (0 votes)
2 views

PHP_Perl_Detailed_Answers

The document is a question paper on PHP and Perl, divided into short and long answer sections. It covers various topics including PHP functions, AJAX, Perl language features, control structures, and database connections. Detailed answers and examples are provided for each question to aid understanding.

Uploaded by

vcvinodrathod
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

PHP_Perl_Detailed_Answers

The document is a question paper on PHP and Perl, divided into short and long answer sections. It covers various topics including PHP functions, AJAX, Perl language features, control structures, and database connections. Detailed answers and examples are provided for each question to aid understanding.

Uploaded by

vcvinodrathod
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

PHP & Perl - Question Paper with Detailed Answers

Section A - Short Answer Questions (10 × 2 = 20 Marks)


(Each question carries 2 marks.)

What does PHP stand for?


PHP stands for 'PHP: Hypertext Preprocessor'. It is a widely-used open-source scripting language
mainly used for web development.

Explain date & time function in PHP.


PHP provides functions like `date()`, `time()`, and `strtotime()` to handle date and time operations.
Example:
```php
echo date('Y-m-d H:i:s'); // Outputs current date and time
echo time(); // Outputs Unix timestamp
```

Define cookies in PHP.


Cookies are small pieces of data stored on the client-side. PHP sets cookies using `setcookie()`
function.
Example:
```php
setcookie('user', 'JohnDoe', time() + (86400 * 30), '/'); // 30-day cookie
```

What are the predefined functions in PHP?


PHP provides many built-in functions:
- String: `strlen()`, `str_replace()`, `substr()`
- Array: `array_merge()`, `count()`
- Math: `abs()`, `pow()`, `sqrt()`

What is AJAX?
AJAX (Asynchronous JavaScript and XML) allows updating web pages without refreshing. It uses
`XMLHttpRequest` to send/receive data asynchronously.

List the advantages of AJAX with PHP.


- Reduces server load
- Improves user experience
- Asynchronous data exchange allows faster interactions
- Supports real-time updates (like chat, notifications)

Define Perl language.


Perl is a general-purpose, high-level scripting language known for text processing, system
administration, and web development.

List different control structure statements in Perl.


- Conditional: `if`, `unless`
- Loops: `for`, `while`, `foreach`
- Jump statements: `next`, `last`

What are the four types of directories in Perl?


1. Current directory (`.`)
2. Parent directory (`..`)
3. Absolute path (`/home/user/folder`)
4. Relative path (`./folder`)

What is index in Perl?


The `index()` function in Perl finds the position of a substring in a string.
Example:
```perl
my $position = index("Hello World", "World"); # Output: 6
print $position;
```

Section B - Long Answer Questions (Any 5 × 10 = 50 Marks)


(Answer any 5 questions. Each question carries 10 marks.)

Explain different mathematical functions in PHP in detail.


PHP provides various mathematical functions to perform calculations.

- **Basic Functions**:
- `abs($num)`: Returns absolute value.
- `ceil($num)`: Rounds up to the nearest integer.
- `floor($num)`: Rounds down to the nearest integer.

- **Example**:
```php
echo abs(-10); // 10
echo ceil(4.2); // 5
echo floor(4.9); // 4
```

Explain in detail about control structures with a suitable example.


Control structures in PHP include conditional statements and loops:

- **If-Else Statement**:
```php
$num = 10;
if ($num > 0) {
echo "Positive";
} else {
echo "Negative";
}
```

Explain the features of PHP MySQL in detail.


- **Open Source**: Free and widely used.
- **Cross-Platform**: Works on Windows, Linux, macOS.
- **Fast & Secure**: Supports transactions, indexing, and strong encryption.

Explain error handling functions in PHP in detail.


- `error_reporting()`: Set error level.
- `set_error_handler()`: Define a custom error handler.

Example:
```php
function customError($errno, $errstr) {
echo "Error: [$errno] $errstr";
}
set_error_handler("customError");
echo $undefinedVar;
```

How can we connect a database using PHP and AJAX? Explain with an example.
**Steps**:
1. Create an HTML form.
2. Use AJAX to send data.
3. Process request in PHP.

**Example:**
**index.html**
```html
<input type='text' id='name'>
<button onclick='sendData()'>Submit</button>
<script>
function sendData() {
let name = document.getElementById('name').value;
let xhr = new XMLHttpRequest();
xhr.open('POST', 'process.php', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.send('name=' + name);
}
</script>
```

Explain how to create a directory and remove a directory with an example.


**Creating a Directory in Perl:**
```perl
mkdir 'new_folder' or die 'Cannot create directory!';
```

**Removing a Directory in Perl:**


```perl
rmdir 'new_folder' or die 'Cannot remove directory!';
```

You might also like