Hi All!
I want to parse from this url: http://youtube.com/rss/global/recently_featured.rss.
But the script prints the items in another order then the original feed (above). Can someone help me please? Thanks a lot!
The following code I use:
<?php
require("MagicParser.php");
function myRecordHandler($record)
{
print_r ($record);
}
$result = MagicParser_parse("http://youtube.com/rss/global/recently_featured.rss","myRecordHandler");
if (!$result)
{
print MagicParser_getErrorMessage();
}
?>
Hi David,
Thanks for your quick answer. But thats the problem! Magic Parser doesnt parse the records in sequence as they appear in de XML-document from YouTube.... I just want the same order of appearing as in the feed from YouTube...
Hi,
What tool are you using to compare the output of the feed from YouTube with the output from Magic Parser. I can assure you that they are returned exactly in the order in which they appear in the feed. To check this, you can look at the feed manually with your browser:
http://youtube.com/rss/global/recently_featured.rss
...and compare this to output of the parsing script:
http://www.magicparser.com/examples/yt1.php
The first 3 items in order in each are (at the moment, it may change of course!);
- SAME DUDE
- Ask A Pumpkin - Billy & Jimmy answer!
- Morph-a-thon Darklight 2007
I will try and help you get the records into the order you want. The previous demo shows how to order the items by PUBDATE. If you want a different order, let me know and i'll help you work out the code to do that...
Cheers,
David.
Hi David.
Thanks for your very good support. Problem is solved, Magic Parser did it right! IE7 didn't show the feed right......
Thanks for you help!
Hi,
The situation here is that YouTube is not generating the feed in date order. Magic Parser will always read the records in sequence as they appear in the XML document. Assuming that you would like to use the items sorted by PUBDATE, what you need to do is first load the items into an array that is indexed by PUBDATE, and then sort that array. You can then loop through the $items array using the foreach construct, and use each $item as you would $record within myRecordHandler. Here's an example:
<?php
require("MagicParser.php");
$items = array();
function myRecordHandler($record)
{
global $items;
$key = strtotime($record["PUBDATE"]);
$items[$key] = $record;
}
$result = MagicParser_parse("http://youtube.com/rss/global/recently_featured.rss","myRecordHandler");
if (!$result)
{
print MagicParser_getErrorMessage();
}
ksort($items);
foreach($items as $item)
{
print_r($item);
}
?>
Hope this helps!
Cheers,
David.