Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
Created April 21, 2017 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phpfiddle/f82686738065f9d3c6e7d3b311b3f01e to your computer and use it in GitHub Desktop.
Save phpfiddle/f82686738065f9d3c6e7d3b311b3f01e to your computer and use it in GitHub Desktop.
[ Posted by Stephanie ] work1 2222
<?php
$url3 = "http://rss.nytimes.com/services/xml/rss/nyt/US.xml"; // xmld.xml contains above data
$feeds3 = file_get_contents($url3);
$rss3 = simplexml_load_string($feeds3);
$items3 = [];
foreach($rss3->channel->item as $entry3) {
$image3 = '';
$image3 = 'N/A';
foreach ($entry3->children('media', true) as $k3 => $v3) {
$attributes3 = $v3->attributes();
if (count($attributes3) == 0) {
continue;
} else {
$image3 = $attributes3->url;
}
$content_data3 = (string)$entry3->children("media", true)->description;
$credit3 = (string)$entry3->children("media", true)->credit;
$creator3 = (string)$entry3->children("dc", true)->creator;
$pubDate3 = (string)$entry3->pubDate;
$pubDate3 = preg_split('/[\s,]+/', $pubDate3);
}
$items3[] = [
'link3' => $entry3->link,
'title3' => $entry3->title,
'image3' => $image3,
'Desc3' =>$content_data3,
'credit3' =>$credit3,
'creator3' =>$creator3,
'pubDate3' =>$pubDate3,
];
}
?>
<?php $i3=0;
foreach ($items3 as $item3) {
if ($i3 < 2) {
printf('<div class="col-sm-6">');
printf('<img src="%s" class="width-100">', $item3['image3']);
printf('<br><a href="%s" target="_blank" class="middle-news-text" >%s</a>', $item3['link3'], $item3['title3']);
printf('<p>%s</p>', $item3['Desc3']);
printf('<span class="reporter">%s</span><span class="date"></span>', $item3['creator3']);
echo $item3['pubDate3'][1]; ?> <?php echo $item3['pubDate3'][2]; ?> <?php echo $item3['pubDate3'][3];
printf('</div>');
$i3++;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment