Dear sir, I am a new user.
I followed the demo and commands to read an external RSS (XML) file, it works alright.
But I need to get all the read content into an array (out of the function) so I can use the data for other purpose. Please guide me... thank you.
Hello Jared,
Sure - the easiest thing to do is to make an array, called $records, of each $record - for example:
<?php
require("MagicParser.php");
$records = array();
function myRecordHandler($record)
{
global $records;
$records[] = $record;
}
MagicParser_parse("rss.xml","myRecordHandler","xml|RSS/CHANNEL/ITEM/");
// and now here all the $record are in the $records array!
?>
...at that point, the foreach() function is the easiest construct to use to access each $record from the $records array, e.g.
foreach($records as $record)
{
print $record["TITLE"];
}
The above may be more complicated than you need, but the basic idea is simply to use global variables if you need to get data out of myRecordHandler - although in most applications it may be worth looking at doing all your processing inside myRecordHandler, and global external information (e.g. file or database handles) in rather than global $record out...
Hope this helps!
Cheers,
David.