SHOW:
|
|
- or go back to the newest paste.
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 | - | $title = (string)$xml->channel->title; |
8 | + | |
9 | $articles[] = sprintf( | |
10 | - | $articles[] = array( |
10 | + | '<li><a href="%s">%s</a><br>%s</li>' . PHP_EOL, |
11 | - | 'url' => (string)$item->url, |
11 | + | $item->link, |
12 | - | 'title' => (string)$item->title, |
12 | + | $item->title, |
13 | - | 'description' => mb_strimwidth( |
13 | + | mb_strimwidth($item->description, 0, 120, '...', 'UTF-8') |
14 | - | (string)$item->description, |
14 | + | |
15 | - | 0, |
15 | + | |
16 | - | 120, |
16 | + | |
17 | - | '...', |
17 | + | $articles[] = '<li>取得失敗</li>'; |
18 | - | 'UTF-8' |
18 | + | |
19 | - | ), |
19 | + | |
20 | shuffle($articles); | |
21 | ||
22 | foreach ($articles as $article) { | |
23 | - | $title = '取得失敗'; |
23 | + | echo $article; |
24 | } |