Skip to content

Instantly share code, notes, and snippets.

@hutattedonmyarm
Created October 24, 2017 17:14
Show Gist options
  • Save hutattedonmyarm/a9493abe508630b3f18e7255326e6e2d to your computer and use it in GitHub Desktop.
Save hutattedonmyarm/a9493abe508630b3f18e7255326e6e2d to your computer and use it in GitHub Desktop.
<?php
$html = file_get_contents('https://wiki.pnut.io/PCA');
$doc = new DOMDocument();
$doc->loadHTML($html);
$tables = $doc->getElementsByTagName('table');
$pca = array();
foreach ($tables as $table) {
if ($table->hasAttribute('class') && $table->getAttribute('class') == 'wikitable') {
foreach ($table->childNodes as $childNode) {
$entry = $childNode->getElementsByTagName('td');
if ($entry->length > 0) {
$achievement["pca"] = $entry->item(0)->textContent;
$achievement["emoji"] = $entry->item(1)->textContent;
$achievement["post_count"] = $entry->item(2)->textContent;
$achievement["inventor"] = $entry->item(3)->textContent;
$pca[] = $achievement;
}
}
}
}
echo json_encode($pca);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment