Passed
Pull Request — master (#36)
by
unknown
07:45
created

my_callback()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
// This example illustrates how to utilize the callback feature to manipulate the DOM
4
include_once '../HtmlWeb.php';
5
use simplehtmldom\HtmlWeb;
6
7
// Write a callback function with one parameter for the element
8
function my_callback($element)
9
{
10
  if ('a' === $element->tag) { // Invalidate all anchors
11
    $element->href = '#';
12
  }
13
}
14
15
// Load the document
16
$doc = new HtmlWeb();
17
$html = $doc->load('https://www.google.com/');
18
19
// Register the callback function
20
$html->set_callback('my_callback');
21
22
// The callback function is invoked automatically when accessing the contents.
23
echo $html;
24