17c06-1.php
来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 37 行
PHP
37 行
<?php// Create a function that will turn an RSS feed, into a definition list:function rss_dl($url) { // Begin by loading the RSS feed into SimpleXML: $rss = simplexml_load_file($url); // Ok, output the title of the feed just as a paragraph block. People // can use stylesheets later to make it look as they wish: echo <<<EOSNIPPET<p> <a href="{$rss->channel->link}">{$rss->channel->title}</a></p>EOSNIPPET; // Now begin our definition list: echo "<dl>\n"; // Loop through all items to make definition entries from them foreach ($rss->channel->item as $i) { // The title with link: echo "<dt><a href=\"{$i->link}\">{$i->title}</a></dt>\n"; // The description as the dd echo "<dd>{$i->description}</dd>\n"; } // End our list now, we are done echo "</dl>\n";}// Test this out:rss_dl('http://acorn.atlantia.sca.org/calendar.xml');// And try it again:echo "<br /><br /><br />\n";rss_dl('http://rss.cnn.com/rss/cnn_topstories.rss');?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?