-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNameRip.php
More file actions
36 lines (29 loc) · 1010 Bytes
/
NameRip.php
File metadata and controls
36 lines (29 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
/**
* Returns the name of the tournament at the requested url, or an empty string if not found.
* @param string $url The base url to the challonge tournament
* @return string
*/
function getName(string $url) {
$playersdata = array();
//Load the HTML from the site
$html = file_get_contents($url);
$dom_document = new DOMDocument();
libxml_use_internal_errors(true);
$dom_document->loadHTML($html);
//use DOMXpath to navigate the html with the DOM
$dom_xpath = new DOMXpath($dom_document);
// if you want to get the div with id=interestingbox
$elements = $dom_xpath->query("//*[@id = 'title']");
if (!is_null($elements) && $elements->length > 0) {
foreach ($elements as $element) {
$nodes = $element->childNodes;
foreach ($nodes as $node) {
return trim($node->nodeValue);
}
}
}
else
return "";
}
?>