I am trying to figure out how to get magicparser to limit the number of items displayed...
is it possible?
I have a question on how to merge that code with this, so I can limit the number of items:
<?php
require("MagicParser.php");
function myRecordHandler($record)
{
print "<tr><td><img src=\"".$record["AUTN:CONTENT/DOCUMENT/IMAGE"]."\"></td>";
print "<td>".$record["AUTN:TITLE"]."</td></tr>";
}
$url = "the-xmlfeed-i-use";
MagicParser_parse($url,"myRecordHandler","xml|AUTNRESPONSE/RESPONSEDATA/AUTN:HIT/")
?>
Thanks,
Tro
Hi Tro,
Here's the limit records code merged with your example:
<?php
require("MagicParser.php");
$counter = 0;
function myRecordHandler($record)
{
global $counter;
print "<tr><td><img src=\"".$record["AUTN:CONTENT/DOCUMENT/IMAGE"]."\"></td>";
print "<td>".$record["AUTN:TITLE"]."</td></tr>";
$counter++;
return ($counter == 3);
}
$url = "the-xmlfeed-i-use";
MagicParser_parse($url,"myRecordHandler","xml|AUTNRESPONSE/RESPONSEDATA/AUTN:HIT/")
?>
Cheers,
David.
Hi murph,
It's no problem - Magic Parser will stop reading any more records if your record handler function returns TRUE. Therefore, all you need to do is setup a global counter and increment it for each record - then return true if the counter has reached the number of items you want to display. For example, to process 3 items only:
<?php
require("MagicParser.php");
$counter = 0;
function myRecordHandler($item)
{
global $counter;
// process $item as required
// increment record counter
$counter++;
return ($counter == 3);
}
MagicParser_parse("file.xml","myRecordHandler");
?>
Hope this helps!
Cheers,
David.