Created
April 21, 2017 15:34
-
-
Save phpfiddle/b6f4d593097b2b8715b9e70740d37dc3 to your computer and use it in GitHub Desktop.
[ Posted by Stephanie ] hogogogoog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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