-
RSS Parser
This is an easy way to convert RSS data to an array so that it is easy to access that data and do stuff with it, enjoy:
PHP Code:
function parse_rss($data) {
$data = iconv('UTF-8', 'UTF-8//IGNORE', $data); // Remove invalid characters
$xml_parser = xml_parser_create();
xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
if (!xml_parse_into_struct($xml_parser, $data, $vals, $index)) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
xml_parser_free($xml_parser);
return $vals;
}
-
To experiment with the above code you could try:
<pre>
PHP Code:
$data = file_get_contents("http://news.google.com/news?pz=1&cf=all&ned=us&hl=en&q=weight+loss&cf=all&output=rss");
$result = parse_rss($data);
print_r($result);