forked from CodeForAfrica/CountySafety
-
Notifications
You must be signed in to change notification settings - Fork 0
/
news.php
54 lines (47 loc) · 1.56 KB
/
news.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
<?php
$rss_tags = array(
'title',
'link',
'guid',
'comments',
'description',
'pubDate',
'category',
);
$rss_item_tag = 'item';
$rss_url = 'http://www.standardmedia.co.ke/rss/crime.php';
$rssfeed = rss_to_array($rss_item_tag,$rss_tags,$rss_url);
//echo '<pre>';
// print_r($rssfeed);
function rss_to_array($tag, $array, $url) {
$doc = new DOMdocument();
$doc->load($url);
$rss_array = array();
$items = array();
foreach($doc->getElementsByTagName($tag) AS $node) {
foreach($array AS $key => $value) {
$items[$value] = $node->getElementsByTagName($value)->item(0)->nodeValue;
}
array_push($rss_array, $items);
}
return $rss_array;
}
$total =1;
?>
<style type='text/css'>
a{
text-decoration:none;
color:red;
}
</style>
<?php
foreach($rssfeed as $item)
{
if($total<10){
echo '<div style="margin-bottom:5px;"><a href="'.$item['link'].'" target="_blank">'.$item['title'].'</a>';
echo '<div style="font-size:0.7em">'.$item['pubDate'].'</div>';
echo $item['description'].'</div>';
$total++;
}
}
?>