Dynadot โ€” .com Registration $8.99

Fopen to curl

Spaceship Spaceship
Watch
Impact
58
I am using this rss parser script to put news on my site. But it looks like my server does not support fopen and I am getting a Warning: fopen error. How can I convert fopen to curl? Or is there another quick and dirty fix?

<?
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") {


print "
<b>" . $this->title . "</b>
<div class=\"text\">" . $this->description . "<br /><a href=\"" . $this->link . "\" target=\"_blank\">Read the Rest of This Story</a></div><br />";

$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.search.yahoo.com/news/rss;_ylt=A0WTTkp6MYRG_asAOAXQtDMD;_ylu=X3oDMTA3MTBsZGZsBHNlYwNhZG0-?p=lawyers&c=&ei=UTF-8&eo=UTF-8","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);


?>
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
What's the fopen error you're getting?
 
0
•••
Warning: fopen

The above error was showing up instead of the news feed. But now my site seems to be working again. Not sure what happened but the problem has resolved itself. Thank you for your input.

On another note, I did some searching around, and I found a free rss news parser script based on curl instead of fopen. I have tried it out and it seems to do the job. I am using it on Amnestybill.com
If anyone wants it let me know and I will post the download link.
 
0
•••
Unstoppable Domains
Domain Recover
NameMaxi - Your Domain Has Buyers
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back