Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: octam
- * Date: 12/5/2017
- * Time: 9:38 PM
- */
- function fetch_news($url) {
- $data = file_get_contents($url);
- $data = simplexml_load_string($data);
- $articles = array();
- foreach ($data->channel->item as $item) {
- $media = $item->children('http://search.yahoo.com/mrss/');
- $image = array();
- foreach ($media->thumbnail[0]->attributes() as $key => $value) {
- $image[$key] = (string)$value;
- }
- $articles[] = array(
- 'title' => (string)$item->title,
- 'description' => (string)$item->description,
- 'link' => (string)$item->link,
- 'date' => (string)$item->pubDate,
- 'image' => $image,
- );
- }
- return $articles;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement