-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnews.php
49 lines (45 loc) · 1.41 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
<!--
* Author : Rohit Shakya
* Date : June-2020
* Editor : Sublime text
* Local server: Xampp
* Title : Blog posting site featuring with Weather and News report
* Version: v5.6
-->
<?php
session_start();
if(!isset($_SESSION['username']))
{
header('Location: home1.html');
}
include_once 'nav.php';
?>
<!--main body-->
<?php
$rss = new DOMDocument(); //https://bavotasan.com/2010/display-rss-feed-with-php/
$rss->load('https://news.google.com/news/rss'); //http://wordpress.org/news/feed/
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
$item = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
);
array_push($feed, $item);
}
$limit = 5;
for($x=0;$x<$limit;$x++) {
$title = str_replace(' & ', ' & ', $feed[$x]['title']);
$link = $feed[$x]['link'];
$description = $feed[$x]['desc'];
$date = date('l F d, Y', strtotime($feed[$x]['date']));
echo '<p><strong><a href="'.$link.'" title="'.$title.'">'.$title.'</a></strong><br />';
echo '<small><em>Posted on '.$date.'</em></small></p>';
echo '<p>'.$description.'</p>';
}
?>
<!--body over-->
<!--section over-->
</body>
</html>