summaryrefslogtreecommitdiff
path: root/tests/xpath.php
blob: 4e422ad2c4d0647eb0bffdfda238a3970740a20d (plain)
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
<?php

$config = array(
    'type' => 'xpath',
    'xpath' => 'div[@itemprop="articleBody"]',
);

$article = array(
    'link' => 'http://www.der-postillon.com/2013/04/nordkoreas-armee-nach-wochenlangem.html',
    'content' => 'This is the feed content',
    'plugin_data' => '',
);

$doc = new DOMDocument();
$html = file_get_contents($article['link']);
$doc->loadHTML($html);

if ($doc) {
    $basenode = false;
    $xpath = new DOMXPath($doc);
    $entries = $xpath->query('(//'.$config['xpath'].')');   // find main DIV according to config

    var_dump($entries);

    if ($entries->length > 0) $basenode = $entries->item(0);

    if ($basenode) {
       $article['content'] = $doc->saveXML($basenode);
       $article['plugin_data'] = "feedmod,$owner_uid:" . $article['plugin_data'];
    }
}

print_r($article);