You can stop Magic Parser by returning TRUE from the record handler function. If you want to read just one record, then simply return TRUE at the end, however if you want to read, say, the first 10 records, create a global counter, increment it each record, and return TRUE when it reaches 10, for example:
In general, it is not possible to tell how many records are in an XML feed without parsing it completely (unless there is a header field that contains the number of items returned).
However, if you are reading the XML into a string before parsing there is a trick you can use to determine the number of records by using substr_count(). For example:
Hi Robert, Sure - drop me an
Hi Robert,
Sure - drop me an email with a link or the feed as an attachment...
Cheers,
David.
Hi David, Thanks alot David
Hi David,
Thanks alot David for your response I have found out what the problem was.
Thanks,
Robert
Hi David, Whats the most
Hi David,
Whats the most efficient way to exit this function from magicParser MagicParser_parse() if an rss had so many records ?
Thanks
Robert,
Hi Robert, You can stop
Hi Robert,
You can stop Magic Parser by returning TRUE from the record handler function. If you want to read just one record, then simply return TRUE at the end, however if you want to read, say, the first 10 records, create a global counter, increment it each record, and return TRUE when it reaches 10, for example:
<?php$counter = 0;
function myRecordHandler($record)
{
$counter++;
return ($counter == 10);
}
?>
Cheers,
David.
Hi David, When using RSS
Hi David,
When using RSS feeds from Ebay how can I tell the total number of records returned in magic parser.
Thanks,
Robert
Hi Robert, In general, it is
Hi Robert,
In general, it is not possible to tell how many records are in an XML feed without parsing it completely (unless there is a header field that contains the number of items returned).
However, if you are reading the XML into a string before parsing there is a trick you can use to determine the number of records by using substr_count(). For example:
<?php$xml = get_file_contents("http://www.example.com/rss.xml");
$numItems = substr_count($xml,"<item>");
?>
...you could then go on to parse the string using MagicParser as follows:
MagicParser_parse("string://".$xml,"myRecordHandler,"xml|RSS/CHANNEL/ITEM/");Cheers,
David.