Php and fopen

software development

#1

I guess the allow_url_fopen disabled security question has been aired often enough in this forum, but I am still stuck! I want to modify a php file with a cURL procedure to put external RSS/XML data from a pre-defined address ($file) into a local file (/feed.html) that I can access using the program’s fopen/fread processes. Here is the relevant snippet from the original code:
[color=#0000CC]
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, “startElement”, “endElement”);
xml_set_character_data_handler($xml_parser, “characterData”);
if (!($fp = fopen($file, “r”))) {
die(“could not open XML input”);
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
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);
[/color]

… and here is my modification:
[color=#0000CC]
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, “startElement”, “endElement”);
xml_set_character_data_handler($xml_parser, “characterData”);
$ch = curl_init($file);
if (!($fp = fopen(“feed.html”, “r”))) {
die(“could not open XML input”);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
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);
[/color]
But what I get back as my output is: "XML error: Empty document at line 1"
I should make it clear that I am not a php programmer: just an average Joe trying to use a common php script, but struggling to make it work with the understandable security restriction set up by Dreamhost. I have been through the wiki and other guidelines, but finding the cURL procedure is not quite as easy as to grasp I thought!
Can anybody see where I have gone wrong?
Thanks … Rod