Advertisement
Guest User

Untitled

a guest
Oct 21st, 2013
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. $url = 'http://www.feedforall.com/sample.xml';
  4. $xml = @simplexml_load_file($url);
  5. $articles = array();
  6.  
  7. if ($xml) {
  8.     foreach ($xml->channel->item as $item) {
  9.         $articles[] = sprintf(
  10.             '<li><a href="%s">%s</a><br>%s</li>' . PHP_EOL,
  11.             $item->link,
  12.             $item->title,
  13.             mb_strimwidth($item->description, 0, 120, '...', 'UTF-8')
  14.         );
  15.     }
  16. } else {
  17.     $articles[] = '<li>取得倱敗</li>';
  18. }
  19.  
  20. shuffle($articles);
  21.  
  22. foreach ($articles as $article) {
  23.     echo $article;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement