Maisonnette » The Meh!


PHP - RSS/Atom feed parser - DOM

Posted in Scripts by The Meh! on the January 30th, 2009

A way to parse RSS or ATOM feeds using “Document Object Model” and output it into array:

<?php
function rss_to_array($tags, $array, $url) {
  /*RSS and ATOM*/
  $doc = new DOMdocument();
  @$doc->load($url);
  $rss_array = array();
  foreach($tags as $tag) {
    if ($doc->getElementsByTagName($tag)) {
      foreach($doc->getElementsByTagName($tag) AS $node) {
        $items = array();
        foreach($array AS $key => $values) {
          $items[$key] = array();
          foreach($values as $value) {
            if ($itemsCheck = $node->getElementsByTagName($value)) {
              for( $j=0 ;  $j < $itemsCheck->length; $j++ ) {
                if (($attribute = $itemsCheck->item($j)->nodeValue) != “”) {
                  $items[$key][] = $attribute;
                } else if ($attribute = $itemsCheck->item($j)->getAttribute(’term’)) {
                  $items[$key][] = $attribute;
                } else if ($itemsCheck->item($j)->getAttribute(’rel’) == ‘alternate’) {
                  $items[$key][] = $itemsCheck->item($j)->getAttribute(’href’);
                }
              }
            }
          }
        }
        array_push($rss_array, $items);
      }
    }
  }
  return $rss_array;
}

$rss_item_tags = array(’item’, ‘entry’);
$rss_tags = array(
  ‘title’ => array(’title’),
  ‘description’ => array(’description’, ‘content’, ’summary’),
  ‘link’ => array(’link’, ‘feedburner’),
  ‘category’ => array(’category’)
);

$rssfeed = rss_to_array($rss_item_tags, $rss_tags, $url);

echo ‘&lt;pre&gt;’;
print_r($rssfeed);
echo ‘&lt;/pre&gt;’;
exit;
?&gt;
Comments Off

Windows 7! Are you kidding?

Posted in Chatterbox by The Meh! on the January 16th, 2009

The so-called new features in (Windows 7) are déjà-vu and even better in Mac long time ago!

Mac OS X Leopard

http://www.apple.com/macosx/features/
http://www.apple.com/macosx/features/300.html

Windows 7

http://www.microsoft.com/windows/windows-7/whats-new.aspx

Comments Off