Advertisement
Guest User

Untitled

a guest
Dec 12th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: octam
  5. * Date: 12/5/2017
  6. * Time: 9:38 PM
  7. */
  8. function fetch_news($url) {
  9. $data = file_get_contents($url);
  10. $data = simplexml_load_string($data);
  11.  
  12. $articles = array();
  13.  
  14. foreach ($data->channel->item as $item) {
  15. $media = $item->children('http://search.yahoo.com/mrss/');
  16.  
  17. $image = array();
  18.  
  19. foreach ($media->thumbnail[0]->attributes() as $key => $value) {
  20. $image[$key] = (string)$value;
  21. }
  22.  
  23. $articles[] = array(
  24. 'title' => (string)$item->title,
  25. 'description' => (string)$item->description,
  26. 'link' => (string)$item->link,
  27. 'date' => (string)$item->pubDate,
  28. 'image' => $image,
  29. );
  30. }
  31. return $articles;
  32. }
  33. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement