RazorSA Posted February 13, 2004 Share Posted February 13, 2004 Hi, On the Neowin.net Home page, www.neowin.net, over .... here Recent posts (x10) rdf filesMain News Backend Gamers Backend Software Backend Forum Backend There are a whole lot of links that generate XML code that I suppose that I can use in my own site, or desktop of whatever. My question: What is the EASIEST way (in PHP script) for me to open one of the links, https://www.neowin.net/backend.php?page=forum and parse all of the information, and then display it in my OWN page in my own way??? Please, any help or examples would be GREAT ... Link to comment Share on other sites More sharing options...
pringlex Posted February 13, 2004 Share Posted February 13, 2004 I came across a similar problem, but with a different application. Here's the code I used, modified a bit for your purpose. It should work! <?php function get_items($page) { $url ="https://www.neowin.net/backend.php?page=$page"; // read the file into a string $allitems = file_get_contents($url); // split the string up into individual items $items = preg_split("/<\/item>/", $allitems); // loop through the array of xml-formatted items // and extract only the data we're interested in. // skip the last entry though, as it's always '</rdf:RDF>' for($i=0; ($i+1)<count($items); $i++) { // make sure everything is on one line or preg_replace will b0rk $items[$i] = str_replace("\n", "", $items[$i]); // get everything between <title> tags $tmptitle = preg_replace("/.*<title>(.*)<\/title>.*/", "\\1", $items[$i]); // convert '&#xxx;' back to 'xx;' $pitems[$i]['title'] = str_replace("&#", "", $tmptitle); // link $tmplink = preg_replace("/.*<link>(.*)<\/link>.*/", "\\1", $items[$i]); // convert '&' to '&' $pitems[$i]['link'] = str_replace("&", "&", $tmplink); } return $pitems; } print_r(get_items("forum")); ?> Link to comment Share on other sites More sharing options...
Recommended Posts