Need help urgent

liunx

Guest
Hi ,
I am using php script for displaying rss feed .. But i am getting following errors while i compile the program...

Warning: simplexml_load_file() [function.simplexml-load-file]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\Apache\Apache2\htdocs\phpProjects\rss.php on line 27

Warning: simplexml_load_file(<!-- m --><a class="postlink" href="http://rss.news.yahoo.com/rss/topstories">http://rss.news.yahoo.com/rss/topstories</a><!-- m -->) [function.simplexml-load-file]: failed to open stream: No such file or directory in C:\Apache\Apache2\htdocs\phpProjects\rss.php on line 27

Warning: No such file or directoryI/O warning : failed to load external entity "http://rss.news.yahoo.com/rss/topstories" in C:\Apache\Apache2\htdocs\phpProjects\rss.php on line 27

yahoo!news




My php code for it is *********

<html>
<style type="text/css">
body { background-image: url("http://www.grsites.com/textures/misc/misc142.jpg"); font-family:Arial; font-size:18px; color:darkred; } ; </style>


<?php



$handle=mysql_connect("172.17.16.73", "root", "abc123") or die ("cant connect");
mysql_select_db("tutorial",$handle) or die ("cant change");


// open database file

// generate and execute query
$query = "SELECT id, title, url, count FROM rss";
$result = mysql_query($query,$handle) or die ("cant connect");
// if records present
if (mysql_num_rows($result) > 0) {

// iterate through resultset
// fetch and parse feed

while($row = mysql_fetch_object($result)) {

$xml = simplexml_load_file('http://rss.news.yahoo.com/rss/topstories');

echo "<h4>$row->title</h4>";

for ($x = 0; $x < $row->count; $x++) {


if (isset($xml->channel->item)) {
$item = $xml->channel->item[$x];
}

echo "<a href=http://www.phpbuilder.com/board/archive/index.php/\"$item->link\">$item->title</a><br />$item->description<p />";
}
echo "<hr />";

// reset variables
unset($xml);
unset($item);
}

}
// if no records present
// display message
else {

?>

<font size = '-1'>No feeds currently configured</font>


<?php

}

// close connection
mysql_close($handle);

?>
</body>
</html>



Do could u suggest me sort out these bugs!!!

I have internet connection and using php5

Thanks in advance..

Regards
mayankDoes Anyone Have Any Clue ??seems pretty simple that your box is having trouble accessing the .rss file.

Your call to simplexml_load_file need not be in the for loop. You should read it once at the top of your file, along with pulling your rss info out of the database. Then use it inside the for loop without re-accessing the foreign file every time.

try this smaller snippit which works for me and see if you can read ANYTHING from yahoo in the first place.


<html>
<body>
<?php
$xml = simplexml_load_file('http://rss.news.yahoo.com/rss/topstories');
if (isset($xml->channel->item)) {
foreach ( $xml->channel->item as $key=>$item ) {
echo "<a href=http://www.phpbuilder.com/board/archive/index.php/\"{$item->link}\">{$item->title}</a><br />";
echo "{$item->description}<br /><hr />";
}
}
?>
</body>
</html>i have used the script written by u.. But even though it is giving same error!!!!!

Warning: simplexml_load_file() [function.simplexml-load-file]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\Apache\Apache2\htdocs\phpProjects\magpierss.php on line 4

Warning: simplexml_load_file(<!-- m --><a class="postlink" href="http://rss.news.yahoo.com/rss/topstories">http://rss.news.yahoo.com/rss/topstories</a><!-- m -->) [function.simplexml-load-file]: failed to open stream: No such file or directory in C:\Apache\Apache2\htdocs\phpProjects\magpierss.php on line 4

Warning: No such file or directoryI/O warning : failed to load external entity "http://rss.news.yahoo.com/rss/topstories" in C:\Apache\Apache2\htdocs\phpProjects\magpierss.php on line 4

What may be the cause?Its quite ovbious it's not the code thats giving the problem, is the computer thats running the php script is having trouble to open "http://rss.news.yahoo.com/rss/topstories"

Test this: In your browser, enter "http://rss.news.yahoo.com/rss/topstories" as the the address, can you see anything?Yes when i browse <!-- m --><a class="postlink" href="http://rss.news.yahoo.com/rss/topstories">http://rss.news.yahoo.com/rss/topstories</a><!-- m --> , i get page containing xml feed.. so url is right.. I think, does problem lies in php installation? even i have register_globals = On and allow_url_fopen = On in php.ini...

I know the its not the code problem but what may casuing error, still not able to figure it out!!Are you browsing from the computer that runs PHP? If not, try that.

You might be able to get a work-around by using simplexml_load_string() and file_get_contents()....

~BrettYes i am browsing it from computer from i am running php..and even i have tried using
it using simplexml_load_string() and file_get_contents() but the result is same.

any idea??No idea. It could be a firewall thing, but I highly doubt it. You hadn't mentioned alternatives, and that's why I suggested it. Sorry I couldn't be of any help.

~Brett
 
Back
Top