-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib_parse.php
64 lines (51 loc) · 1.36 KB
/
lib_parse.php
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
* InfoAppl Bulletin Board Bot
* ===================
* UWiClab, University of Urbino
* ===================
* Parsing function collection.
*/
function get_element_value($node, $nodeTag){
$elNodes = $node->GetElementsByTagName($nodeTag);
if( $elNodes->length < 1){
die("Parsing Error");
}
return $elNodes->item(0)->nodeValue;
}
function get_title($node){
return get_element_value($node, 'title');
}
function get_pubDate($node){
return new DateTime(get_element_value($node, 'pubDate'));
}
function get_link($node){
return get_element_value($node, 'link');
}
function get_description($node){
return get_element_value($node, 'description');
}
function get_content_encoded($node){
return get_element_value($node, 'encoded');
}
function get_guid($node){
return extract_guid_number(get_element_value($node, 'guid'));
}
function get_feed_news($url){
$doc = new DOMDocument();
if($doc->load($url) === false){
die("Error loading feed");
}
$xpath = new DOMXPath($doc);
$news = array();
foreach( $xpath->query( '//item') as $node){
// $node is DOMElement
$nn = new News();
$nn->title = get_title($node);
$nn->pubDate = get_pubDate($node);
$nn->link = get_link($node);
$nn->guid = get_guid($node);
$news []= $nn;
}
return $news;
}