note 111375 added to function.xml-parse-into-struct
| From: | CyberSEO.net | Date: | Wed, 13 Feb 2013 14:52:59 +0000 |
| Subject: | note 111375 added to function.xml-parse-into-struct | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-193624@lists.php.net to get a copy of this message | ||
Here is the World's smallest (I hope so :)) RSS parser with caching.
// Put your RSS feed URL here:
$feed = "http://rss.cnn.com/rss/cnn_topstories.rss";
// Assign the local path to your optional cache file
$filename = "cache.txt";
// The default cache refresh time (e.g. 1 hour)
if (file_exists($filename) && filesize($filename) && (time() - filectime($filename))
< 60 * 60) {
$content = file_get_contents($filename);
} else {
$xml_parser = xml_parser_create();
xml_parse_into_struct($xml_parser, file_get_contents($feed), $vals, $index);
xml_parser_free($xml_parser);
// The maximum number of displayed items (e.g. 5).
$cnt = min(5, count($index["TITLE"]));
$content = "";
for ($i = 1; $i < $cnt; $i++) {
$content .= "<h3>" .
html_entity_decode($vals[$index["TITLE"][$i]]["value"], ENT_QUOTES) .
"</h3>\n";
$content .= "<p>" .
html_entity_decode($vals[$index["DESCRIPTION"][$i]]["value"], ENT_QUOTES) .
"</p>\n";
}
file_put_contents($filename, $content, LOCK_EX);
}
echo $content;
----
Server IP: 69.147.83.199
Probable Submitter: 173.214.255.81
----
Manual Page -- http://php.net/manual/en/function.xml-parse-into-struct.php
Edit -- https://master.php.net/note/edit/111375
Del: integrated -- https://master.php.net/note/delete/111375/integrated
Del: useless -- https://master.php.net/note/delete/111375/useless
Del: bad code -- https://master.php.net/note/delete/111375/bad+code
Del: spam -- https://master.php.net/note/delete/111375/spam
Del: non-english -- https://master.php.net/note/delete/111375/non-english
Del: in docs -- https://master.php.net/note/delete/111375/in+docs
Del: other reasons-- https://master.php.net/note/delete/111375
Reject -- https://master.php.net/note/reject/111375
Search -- https://master.php.net/manage/user-notes.php