
April 28th, 2003, 01:06 PM
|
 |
I'm Internet Famous
|
|
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890
 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
|
|
jpenn,
i was following this tutorial earlier and ran into this problem:
Quote:
Warning: php_hostconnect: connect failed in e:\pub\public_html\rss\sitepointcover.php on line 51
Warning: fopen("http://www.sitepoint.com/rss.php", "r") - Bad file descriptor in e:\pub\public_html\rss\sitepointcover.php on line 51
Error reading RSS data. |
Line 51 refers to this:
$fp = fopen("http://www.sitepoint.com/rss.php","r")
i checked the PHP function reference for fopenand "r" is indeed a valid file descriptor... what else might my problem be? I used the code directly from the tutorial, infact... http://www.webmasterbase.com/exampl...over-oo.php.txt links to their source code... i found i had to right click and save as to view it properly.
[for people not reading the tutorial, here's my script:]
PHP Code:
<?php
$insideitem = false;
$tag = "";
$title = "";
$description = "";
$link = "";
function startElement($parser, $name, $attrs) {
global $insideitem, $tag, $title, $description, $link;
if ($insideitem) {
$tag = $name;
} elseif ($name == "ITEM") {
$insideitem = true;
}
}
function endElement($parser, $name) {
global $insideitem, $tag, $title, $description, $link;
if ($name == "ITEM") {
printf("<dt><b><a href='%s'>%s</a></b></dt>",
trim($link),htmlspecialchars(trim($title)));
printf("<dd>%s</dd>",htmlspecialchars(trim($description)));
$title = "";
$description = "";
$link = "";
$insideitem = false;
}
}
function characterData($parser, $data) {
global $insideitem, $tag, $title, $description, $link;
if ($insideitem) {
switch ($tag) {
case "TITLE":
$title .= $data;
break;
case "DESCRIPTION":
$description .= $data;
break;
case "LINK":
$link .= $data;
break;
}
}
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
$fp = fopen("http://www.sitepoint.com/rss.php","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);
?>
Last edited by MadCowDzz : April 28th, 2003 at 01:09 PM.
|