I'm having a problem...
Date: 04/28/05
(PHP Community) Keywords: mysql, rss, html, xml, database, sql
Alright, I'm having a bit of a problem.
I've set up a page to read and parse RSS feeds. It works for the most part. The feed names and addresses are pulled from a mysql database okay. The problem lies in putting them onscreen. At some point, variables are not being dropped or overwritten, and I'm getting the same results repeated, but with the count number of the second feed.
See what I mean?
This is the code:
-- Begin Code --
include (" [ sql stuff ]");
$sql = "SELECT * FROM rss_feeds";
$results = mysql_query($sql);
while ($myrow = mysql_fetch_array($results))
{
$feedtitle = $myrow['name'];
$feedurl = $myrow['url'];
$xfeed = $myrow["feed"];
$maxcount = $myrow['num_items'];
$xmlfile = fopen("$xfeed", "r");
if(!$xmlfile)die("This doesn't work");
$readfile = fread($xmlfile ,100000);
$searchfile = eregi("< item>(.*)< /item>", $readfile ,$arrayreg);
$filechunks = explode("< item>", $arrayreg[0]);
$count = count($filechunks);
if ($maxcount > $count)
{
$maxcount = $count;
}
echo "< a href=\"$feedurl\">$feedtitle< /a>< br>";
for($i=1 ; $i<=$maxcount ; $i++)
{
eregi("< title>(.*)< /title>",$filechunks[$i], $title);
eregi("< link>(.*)< /link>",$filechunks[$i], $link);
eregi("< pubDate>(.*)< /pubDate>",$filechunks[$i], $pubdate);
eregi("< description>(.*)< /description>",$filechunks[$i], $description);
$pubdate = "$pubdate[1]";
$xlink = "$link[1]";
$xtitle = "$title[1]";
$xdescription = "$description[1]";
$xdescription = html_entity_decode($xdescription);
$xdescription = strip_tags($xdescription);
$xday = substr($pubdate, 5, 2);
$xmonth = substr($pubdate, 8, 3);
$xyear = substr($pubdate, 12, 4);
$monthnames = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
$monthnumbers = array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12");
$ymonth = str_replace($monthnames, $monthnumbers, $xmonth);
$articledate = date("F jS, Y", mktime(0, 0, 0, $ymonth, $xday, $xyear));
echo "< span style=\"text-transform: capitalize;\">< a href =\"$xlink\" target=\"_blank\">$xtitle< /a>< /span>< br>";
echo "$articledate< br>";
echo "$xdescription< br>";
}
}
-- End Code --
Anyone have any idea what could be causing this?
NOTE: It looks now to be a problem with the one RSS feed itself, and not the code
Source: http://www.livejournal.com/community/php/292485.html