You are here:  » Magic Parser is not parsing the items from new to old


Magic Parser is not parsing the items from new to old

Submitted by King Bukkum on Wed, 2007-08-15 19:46 in

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();
}
?>

Submitted by support on Wed, 2007-08-15 21:54

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.

Submitted by King Bukkum on Thu, 2007-08-16 13:40

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...

Submitted by support on Thu, 2007-08-16 14:21

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.

Submitted by King Bukkum on Thu, 2007-08-16 21:49

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!