element; the value of each entry is an * array of the attribute name/value pairs from the * outline. For instance: * * $_BLOGROLL['foo'] = * ['TITLE'] => 'foo' * ['DESCRIPTION'] => 'from the outline' * ['HTMLURL'] => 'http://example.com/blog/' * * et cetera. */ print "\n"; } $status = count($_BLOGROLL); /* * Nuke the global cell (ptui, ptui!) */ $_BLOGROLL = null; return $status; } /* * You shouldn't need to change anything from this point on. */ /* * Parse the OPML file and extract the outlines from it. */ function parse_opml($file) { $fp = @fopen($file, 'rB'); if (! $fp) { return false; } $opml = fread($fp, 1000000); $xp = xml_parser_create(); xml_set_element_handler($xp, '_xml_startElement', '_xml_endElement'); xml_parse($xp, $opml, true); xml_parser_free($xp); return true; } /* * Helper functions for parsing the OPML file (which is XML). * It's too bad we have to pollute the global namespace (variable * $_BLOGROLL), but that's a limitation. I tried doing this OO * inside an object, but indirect call-by-name apparently requires * global function names. Sigh. * * Basically, add each outline to the $_BLOGROLL array, using * the outline 'title' attribute as the key. */ function _xml_startElement($xp, $element, $attr) { global $_BLOGROLL; /* * If it isn't an element, ignore it. */ if (strcasecmp('outline', $element)) { return; } $_BLOGROLL[$attr['TITLE']] = $attr; } function _xml_endElement($xp, $element) { return; } /* * Local Variables: * mode: C * c-file-style: "bsd" * tab-width: 4 * indent-tabs-mode: nil * End: */ ?>