my code is designed to goto a page and extract data from the forum and put it into a rss feed
but it gets to a point where it runs out of variables and uses the last one it knew to use
let me explain a little better
it is supposed to grab date, name of poster, and forum and subject
well sometimes towards the bottom it says posted by the same person for 5 in a row and under the wrong forum
ex:
WoltLab GmbH posted about 'dexter021 vs. BloodHunter' in the Artistic Impressions forums.
WoltLab GmbH posted about 'POLL - Choose your favourite Olympian God' in the Artistic Impressions forums.
neither of these echos should be by this person or in this forum
here is my code
anyone that can help is much appricated
<?
header("Content-Type: application/xml; charset=ISO-8859-1");
function EncodeXmlEntities($str) {
return str_replace(
array ('&', '"', "'", '<', '>' ),
array ('&', '"', ''' , '<' , '>' ),
$str
);
}
define('CACHE_TIME', 5 * 60); // Cache time in seconds (5 mins)
define('CACHE_FILE', 'bf.cache'); // Where we store a local copy of the feed for caching purposes(can change)
if (time() - filemtime(CACHE_FILE) < CACHE_TIME) // Is our cache file new enough to use?
{
$result = file_get_contents(CACHE_FILE); // Use cache (html code from our $destination)
} else {
// Cache expired, download new copy, and grab its contents ($result)
$result = file_get_contents('http://board.bitefight.org/search.php?action=24h');
$fp= fopen(CACHE_FILE, 'w'); //Dump html source code to cachfile
fwrite ($fp, $result); //Dump html source code to cachfile
fclose($fp); //Dump html source code to cachfile
}
$now = date("D, d M Y H:i:s") ." EST";
$rss =
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" .
"<rss version=\"2.0\">" .
"<channel>" .
"<title>Bite Fight RSS</title>" .
"<description>Bite Fight's Forum</description>" .
"<link>http://board.bitefight.org</link>" .
"<language>en-us</language>" .
"<generator>http://www.pappyspage.com</generator>" .
"<lastBuildDate>$now</lastBuildDate>" .
"<ttl>" .(CACHE_TIME / 60) ."</ttl>";
for($i=0;$i<20;$i++)
{
//Get thred number
$thrednumb = ' <a href="thread.php?threadid=';
$thrednume = '&goto=lastpost';
if ( ( $pos1 = strpos ( $result, $thrednumb ) ) !== false)
{
$result1 = substr ( $result, ( $len1 = ( $pos1 + strlen ( $thrednumb ) ) ), ( strpos ( $result, $thrednume, $len1 ) - $len1 ) );
}
//Get thred number
//Get date
$postdateb = '<td align="right" nowrap="nowrap"><span class="smallfont"><b>';
$postdatee = '</b>';
if ( ( $pos2 = strpos ( $result, $postdateb ) ) !== false)
{
$result2 = substr ( $result, ( $len2 = ( $pos2 + strlen ( $postdateb ) ) ), ( strpos ( $result, $postdatee, $len2 ) - $len2 ) );
}
//Get date
//Get forum
$forumnameb = '<br />Forum:';
$forumnamee = '</a>';
if ( ( $pos3 = strpos ( $result, $forumnameb ) ) !== false)
{
$result3 = substr ( $result, ( $len3 = ( $pos3 + strlen ( $forumnameb ) ) ), ( strpos ( $result, $forumnamee, $len3 ) - $len3 ) );
}
//Get forum
//Get time
$posttimeb = '<span class="time">';
$posttimee = '</span>';
if ( ( $pos4 = strpos ( $result, $posttimeb ) ) !== false)
{
$result4 = substr ( $result, ( $len4 = ( $pos4 + strlen ( $posttimeb ) ) ), ( strpos ( $result, $posttimee, $len4 ) - $len4 ) );
}
//Get time
//Get poster
$posterb = 'by <b>';
$postere = '</a>';
if ( ( $pos5 = strpos ( $result, $posterb ) ) !== false)
{
$result5 = substr ( $result, ( $len5 = ( $pos5 + strlen ( $posterb ) ) ), ( strpos ( $result, $postere, $len5 ) - $len5 ) );
//Get poster
//Get subject
}
$postsubb = '</span>
<a';
$postsube = '</a>';
if ( ( $pos6 = strpos ( $result, $postsubb ) ) !== false)
{
$result6 = substr ( $result, ( $len6 = ( $pos6 + strlen ( $postsubb ) ) ), ( strpos ( $result, $postsube, $len6 ) - $len6 ) );
}
//Get subject
$result = str_replace($thrednumb . $result1 . $thrednume, '~', $result);
$result = str_replace($postdateb . $result2 . $postdatee, '~~', $result);
$result = str_replace($forumnameb . $result3 . $forumnamee, '~~~', $result);
$result = str_replace($posttimeb . $result4 . $posttimee, '~~~~', $result);
$result = str_replace($posterb . $result5 . $postere, '~~~~~', $result);
$result = str_replace($postsubb . $result6 . $postsube, '~~~~~~', $result);
$strip1 = strip_tags($result1);
$strip2 = strip_tags($result2);
$strip3 = strip_tags($result3);
$strip4 = strip_tags($result4);
$strip5 = strip_tags($result5);
$result6 = '<a' .$result6;
$strip6 = strip_tags($result6);
$strip1 = "http://board.bitefight.org/thread.php?threadid=" .$strip1. "&goto=lastpost";
$descr = $strip5 . " posted about '" . $strip6 . "' in the " . $strip3 . " forums.";
$rss .=
"<item>" .
"<title>" .EncodeXmlEntities($strip6) ."</title>" .
"<link>" .EncodeXmlEntities($strip1) ."</link>" .
"<guid>" .EncodeXmlEntities($strip1) ."</guid>" .
"<description>" .EncodeXmlEntities($descr) ."</description>" .
"<pubDate>" .EncodeXmlEntities($strip2) . " @ " . EncodeXmlEntities($strip4) . " GMT(+1)" . "</pubDate>" .
"</item>";
}
// Footer.
$rss .=
"</channel>" .
"</rss>";
echo $rss;
?>
ive tried using preg replace with a limit of 1 but that makes the value blank
thx in advance