Skip to content

Instantly share code, notes, and snippets.

@ceceprawiro
Created July 20, 2016 05:51
Show Gist options
  • Save ceceprawiro/bc313e9af17852b5b651eed654810391 to your computer and use it in GitHub Desktop.
Save ceceprawiro/bc313e9af17852b5b651eed654810391 to your computer and use it in GitHub Desktop.
<?php
$url = "http://simas.bandaacehkota.go.id/index.php?mod=masjid&act=json_masjid&order=asc&offset=0";
$source = file_get_contents($url);
$data = json_decode($source);
$total = $data->total;
foreach ($data->rows as $row) {
$row->images = fetch_images($row->id);
debug($row);
}
function fetch_images($id)
{
$url = "http://simas.bandaacehkota.go.id/index.php?mod=masjid&act=page&id={$id}";
$source = file_get_contents($url);
$dom = new DOMDocument();
@$dom->loadHTML($source);
$xpath = new DOMXPath($dom);
$nodes = $xpath->query("//div[contains(@class, 'item')]/img");
$images = [];
foreach ($nodes as $node) {
$images[] = $node->getAttribute('src');
}
return $images;
}
function debug($var, $method = 'print_r')
{
echo '<pre>';
$method($var);
echo '</pre>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment