Advance PHP Detailed Final
Advance PHP Detailed Final
- PHP DOM (Document Object Model) allows manipulating XML and HTML documents.
- Important functions:
1. **DOM Parser**: Reads the entire XML document into memory and provides tree-based
parsing.
- AJAX (Asynchronous JavaScript and XML) allows dynamic updates without page reloads.
- Advantages:
- **Faster Performance**: Updates only required data instead of reloading the entire page.
- **Works with JSON & XML**: Compatible with modern data formats.
- Common elements:
- A self-processing form submits data to the same script that processes it.
- Example:
```php
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST['name'];
} else {
?>
</form>
<?php } ?>
```
- **GET Method**:
- **POST Method**:
- Example:
```php
class Car {
public $brand;
$this->brand = $brand;
return $this->brand;
}
}
echo $myCar->getBrand();
```
- XML Structure:
- Example:
```xml
<library>
<book>
<title>PHP Basics</title>
<author>John Doe</author>
</book>
</library>
```
- AJAX allows web applications to update content dynamically without refreshing the page.
- Steps:
- **HTML + JavaScript**:
```html
<button onclick="calculateSum()">Add</button>
<p id="result"></p>
<script>
function calculateSum() {
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.onload = function() {
};
</script>
```
- **PHP (add.php)**:
```php
<?php
?>
```
- Example:
```php
```
- Using MySQLi:
```php
```
- `include()`: Includes a file but does not stop execution if the file is missing.