Click to See Complete Forum and Search --> : this used to work, now all of the sudden it doesn't. :(


Chaos343
08-16-2005, 03:37 PM
a few months ago i found this code that puts some rss news headlines on my site. it used to work perfect! now all of the sudden, it does not do anything and i have not changed it! anyone know what's going on? TIA. here is the code:


<?

// The @ is to supress the function´ errors

$newsfeed = 'http://rss.news.yahoo.com/rss/business';

$fp = @fopen($newsfeed, 'r');
while(!feof($fp)){
$row .= @fgets($fp, 4096);
}
@fclose($fp);

if( eregi('<item>(.*)</item>', $row, $rowitem ) ) {
$item = explode('<item>', $rowitem[0]);

for( $i = 5; $i < count($item) - 1; $i++ ) {

eregi('<title>(.*)</title>', $item[$i+1], $title );
eregi('<link>(.*)</link>', $item[$i+1], $link );
eregi('<pubDate>(.*)</pubDate>', $item[$i+1], $pubDate);

echo '<table width="468" border="0" cellpadding="3" cellspacing="0" bgcolor="#FFFFFF"><tr><td align="center"><a href="' . $link[1] . '" target="_blank"><b>' . $title[1] . '</b></a><br>';
echo '' . $pubDate[1] . '</td></tr></table>';

}
}

?>

bokeh
08-16-2005, 04:38 PM
Maybe short tags has been switched off on your server. Try starting with <?php

NogDog
08-16-2005, 04:43 PM
A few changes I'd try to see if you can narrow down where the problem is (my changes commented with "# <<"

<?php # << some configs require full php tag, so safest to always us it
error_reporting(E_ALL); # << for now have PHP report all errors
// The @ is to supress the function´ errors
# << if you're going to use @, then you'd best do your own error-checking

$newsfeed = 'http://rss.news.yahoo.com/rss/business';

$fp = @fopen($newsfeed, 'r') or die("fopen($newfeed) failed"); # << look for error
while(!feof($fp)){
$row .= @fgets($fp, 4096);
}
@fclose($fp);

if( eregi('<item>(.*)</item>', $row, $rowitem ) ) {
$item = explode('<item>', $rowitem[0]);

for( $i = 5; $i < count($item) - 1; $i++ ) {

eregi('<title>(.*)</title>', $item[$i+1], $title );
eregi('<link>(.*)</link>', $item[$i+1], $link );
eregi('<pubDate>(.*)</pubDate>', $item[$i+1], $pubDate);

echo '<table width="468" border="0" cellpadding="3" cellspacing="0" bgcolor="#FFFFFF"><tr><td align="center"><a href="' . $link[1] . '" target="_blank"><b>' . $title[1] . '</b></a><br>';
echo '' . $pubDate[1] . '</td></tr></table>';

}
}

?>

Chaos343
08-16-2005, 05:25 PM
i just tried using the code NogDog posted.

now it says: "Notice: Undefined variable: row on line 10"

line 10 is this:

$row .= fgets($fp, 4096);

i'm thinking something either changed with my server or the format of the yahoo rss feed, since it used to work and i didn't change anything.

bokeh
08-16-2005, 06:01 PM
Change this:
while(!feof($fp)){
$row .= @fgets($fp, 4096);
}
@fclose($fp);

to this:
$row = '';
while(!feof($fp)){
$row .= @fgets($fp, 4096);
}
@fclose($fp);