corsasport.co.uk
 

Corsa Sport » Message Board » Off Day » php xml parser (help needed pls)


New Topic

New Poll
  Subscribe | Add to Favourites

You are not logged in and may not post or reply to messages. Please log in or create a new account or mail us about fixing an existing one - register@corsasport.co.uk

There are also many more features available when you are logged in such as private messages, buddy list, location services, post search and more.


Author php xml parser (help needed pls)
Houckham
Member

Registered: 29th May 03
Location: Newcastle upon Tyne
User status: Offline
   30th Nov 04 at 20:22   View User's Profile U2U Member Reply With Quote

i got this code off a website and it says it works ive edited the url for the rss feed and uploaded it but it doesnt work.
im getting an error :

Warning: fopen(): URL file-access is disabled in the server configuration in /customers/nufc-forum.com/nufc-forum.com/httpd.www/rss_test.php on line 60

Anyone know if it can be fixed? or know of asimpler way to parse an XML feed/RSS

thanx

heres the code



code:

<?php

class RSSParser {

var $insideitem = false;
var $tag = "";
var $title = "";
var $description = "";
var $link = "";

function startElement($parser, $tagName, $attrs) {
if ($this->insideitem) {
$this->tag = $tagName;
} elseif ($tagName == "ITEM") {
$this->insideitem = true;
}
}

function endElement($parser, $tagName) {
if ($tagName == "ITEM") {
printf("<dt><b><a href='%s'>%s</a></b></dt>",
trim($this->link),htmlspecialchars(trim($this->title)));
printf("<dd>%s</dd>",htmlspecialchars(trim($this->description)));
$this->title = "";
$this->description = "";
$this->link = "";
$this->insideitem = false;
}
}

function characterData($parser, $data) {
if ($this->insideitem) {
switch ($this->tag) {
case "TITLE":
$this->title .= $data;
break;
case "DESCRIPTION":
$this->description .= $data;
break;
case "LINK":
$this->link .= $data;
break;
}
}
}
}

$xml_parser = xml_parser_create();
$rss_parser = new RSSParser();
xml_set_object($xml_parser,&$rss_parser);
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
$fp = fopen("http://news.bbc.co.uk/rss/newsonline_world_edition/uk_news/rss091.xml'","r")
or die("Error reading RSS data.");
while ($data = fread($fp, 4096))
xml_parse($xml_parser, $data, feof($fp))
or die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
fclose($fp);
xml_parser_free($xml_parser);

?>?>


[Edited on 30-11-2004 by Houckham]
James_DT
Member

Registered: 9th Apr 04
Location: Cambridgeshire
User status: Offline
30th Nov 04 at 20:50   View User's Profile U2U Member Reply With Quote

Server is setup to not allow you to use fopen to access remote files.
Houckham
Member

Registered: 29th May 03
Location: Newcastle upon Tyne
User status: Offline
30th Nov 04 at 20:58   View User's Profile U2U Member Reply With Quote

is there a way i can change this so it allows it?
Dom
Member

Registered: 13th Sep 03
User status: Offline
30th Nov 04 at 22:15   View User's Profile U2U Member Reply With Quote

unless its your own server, then no there isnt.
however, you can retrieve the XML file remotely and then parse it through that script (obviously take out the bits where it opens the remote file etc)
Have a butchers >> HERE << on how to retrieve a remote file

 
New Topic

New Poll

Corsa Sport » Message Board » Off Day » php xml parser (help needed pls) 23 database queries in 0.0122161 seconds