Hi David,
Magic Parser works great, but I do have a problem parsing a Zanox affiliate file.
The error I get is: PHP Fatal error: Call to undefined function: myrecordhandler() in /var/www/vhosts/bijnavakantie.nl/httpdocs/feed/MagicParser.php on line 2
I use the following php code snippets:
<?php
require("MagicParser.php");
$records = array(); // global array of records to pick from later
MagicParser_parse("http://www.bijnavakantie.nl/feed/cache.php?id=Elmar&cachetime=1440","myRecordHandler","xml|ZANOX/PRODUCT/");
shuffle($records);
// now you pick off as many random records as you require....
?>
<?php
include_once("/var/www/vhosts/bijnavakantie.nl/httpdocs/feed/elmar_feed.php");
$count = 0;
foreach ($records as $record) {
echo '<h4><a href="'.$record["LINKS/DEEPLINK"].'" target="_blank">'.$record["INFO/NAME"].', '.$record["CATEGORY/MERCHANT"].' ('.$record["INFO/EXTRATEXT"].')</a></h4>';
echo 'Vanaf '.$record["OFFER/CURRENTPRICE"].''.$record["PRICE-CURRENCY"].' p.p.';
$count++;
if ($count == 5) break;
}
?>
Do you have any idea what could be wrong?
/Jasper
That did the trick. Missed that part of code here. Thanks David!
Hello Jasper,
Your second snippet looks as it it expecting a record handler function to have loaded all $record arrays into a global array of $records, So somewhere you should have something like this
<?php
$records = array();
function myRecordHandler($record)
{
global $records;
$records[] = $record;
}
?>
Alternatively, without the foreach loop, your section of code in the second snippet can act as your record handler function, for example:
<?php
include_once("/var/www/vhosts/bijnavakantie.nl/httpdocs/feed/elmar_feed.php");
$count = 0;
function myRecordHandler($record)
{
global $count;
echo '<h4><a href="'.$record["LINKS/DEEPLINK"].'" target="_blank">'.$record["INFO/NAME"].', '.$record["CATEGORY/MERCHANT"].' ('.$record["INFO/EXTRATEXT"].')</a></h4>';
echo 'Vanaf '.$record["OFFER/CURRENTPRICE"].''.$record["PRICE-CURRENCY"].' p.p.';
$count++;
if ($count == 5) return TRUE;
}
?>
Hope this helps!
Cheers,
David.