Getting an RSS feed with the Zend framework 0.1.1.

March 5th, 2006. Tagged: Zend framework

In case you've missed it, the fisrt pre-release of the Zend PHP framework went public. I briefly looked into it and here's a quick example to get you started.

Download and install

Nothing complicated with the installation, you just get a folder full of PHP goodies and make it available to your scripts.

  1. Get the zip/tar.gz from the framework site
  2. Uncompress somewhere. You'll see 4 folders in the package - demos (some example scripts), documentation, incubator (pre-relase libraries) and library (the real thing)
  3. Copy library somewhere and add it to your include path or just put it in your test scripts directory and have your script set the include path

Personally I simply created a zsandbox in my www and pasted the library in it. Something like:
my web root - C:\apache\htdocs
my test dir - C:\apache\htdocs\zsandbox
the library - C:\apache\htdocs\zsandbox\library

Then in my C:\apache\htdocs\zsandbox\test.php script (accessible as http://localhost/zsandbox/test.php), I started with:

set_include_path(
    get_include_path() . ';library'
)

Don't forget to change ; to : if you're on Linux.

Printing my RSS feed

There is the Zend_Feed package in the library. I played with it to print the contents of this blog's RSS feed. Here's how I did it.

<?php
// set error reporting
error_reporting(E_ALL);
// append 'library' to the current include path
set_include_path(
    get_include_path() . ';library'
);

// get the feed library
require_once 'Zend/Feed.php';

try {
    // get the rss feed
    $rss = Zend_Feed::import('http://www.phpied.com/feed');
} catch (Exception $e) {
    // oops
    echo $e->getMessage();
    exit;
}

// Loop through the items in the feed
foreach ($rss as $item) {
    $items[] = array(
        'title'       => $item->title(),
        'link'        => $item->link(),
    );

}
// var_dump all items
Zend::dump($items);
?>

And the result is:

array(10) {
  [0] => array(2) {
    ["title"] => string(51) "Getting an RSS feed with the  Zend framework 0.1.1."
    ["link"] => string(46) "http://www.phpied.com/rss-feed-zend-framework/"
  }
  [1] => array(2) {
    ["title"] => string(33) "toAjax() in about 6 hours 49 mins"
    ["link"] => string(47) "http://www.phpied.com/to-ajax-in-about-6-hours/"
  }
  [2] => array(2) {
    ["title"] => string(32) "Bitwise operations in JavaScript"
    ["link"] => string(55) "http://www.phpied.com/bitwise-operations-in-javascript/"
  }
  [3] => array(2) {
    ["title"] => string(30) "RGB color parser in JavaScript"
    ["link"] => string(53) "http://www.phpied.com/rgb-color-parser-in-javascript/"
  }
  [4] => array(2) {
    ["title"] => string(9) "coComment"
    ["link"] => string(32) "http://www.phpied.com/cocomment/"
  }
  [5] => array(2) {
    ["title"] => string(27) "Light color fonts in inputs"
    ["link"] => string(50) "http://www.phpied.com/light-color-fonts-in-inputs/"
  }
  [6] => array(2) {
    ["title"] => string(20) "AJAX banner rotation"
    ["link"] => string(43) "http://www.phpied.com/ajax-banner-rotation/"
  }
  [7] => array(2) {
    ["title"] => string(17) "Better time input"
    ["link"] => string(44) "http://www.phpied.com/javascript-time-input/"
  }
  [8] => array(2) {
    ["title"] => string(9) "DB-2-MDB2"
    ["link"] => string(32) "http://www.phpied.com/db-2-mdb2/"
  }
  [9] => array(2) {
    ["title"] => string(38) "Chicken Soup for the Programmer's Soul"
    ["link"] => string(60) "http://www.phpied.com/chicken-soup-for-the-programmers-soul/"
  }
}

Next?

Not bad, eh? So what next? I think the best thing to do it to browse through the manual (scroll down for the examples) and just experiment to get the feel of it.

So far if you ask me, it feels a lot like PEAR, plus MVC on top, but I haven't yet played with the view-controller stuff yet. And it's PHP5 only, which is probably a good thing (hosting companies adoption aside).

p.s. Make sure you read this Andi Gutman's posting to see how to correct a small late-night refactoring issue that slipped into the initial 0.1.1. release of the framework.

Tell your friends about this post: Facebook, Twitter, Google+

14 Responses

  1. [...] А вот и первый пример того, как оно работает с новостными фидами. Вроде не сложно совсем, вот только по моему они наступили с Zend_Feed на грабельки с кодировками, хотя я могу ошибаться… Посмотрим в будущем, когда выйдет версия 1.0. [...]

  2. It looks nice but I wonder how long it will take before this thing is mature enough to use in a real production environment. Right now frameworks like Cake or Symfony seem to be miles ahead of where the Zend Framework is right now.

    Its kinda tough. I guess we all want a standard framework but as far as Im concerned I want it now, or at least real soon now….

    http://www.i-marco.nl/weblog/archive/2006/02/23/which_php_framework_holds_a_pr

    note: I still cannot post anything containing single quotes here….

  3. Zend Framework – wejście smoka…

    Kilka dni temu została opublikowana pierwsza wersja zapowiadanego od dluższego czasu Zend Framework oznaczona numerkiem 0.1.1. Podszedłem do tego dość sceptycznie i z dystansem, bo publikacja tak wczesnej wersji mogła okazać się niewypałem, a …

  4. very nice intro! muchas gracias :)

  5. this script show error on run

    class ‘Zend’ not found in /home/eugene/seo_project/music_rss/rss_music.php on Zend::dump($items);

  6. i think that RSS FEEDS should also be included on the list of the best inventions because it makes life easier for bloggers like us ,.,

  7. hey there and thank you for your information – I have definitely picked up anything new from right here. I did however expertise several technical issues using this web site, since I experienced to reload the web site many times previous to I could get it to load properly. I had been wondering if your hosting is OK? Not that I am complaining, but slow loading instances times will often affect your placement in google and can damage your high quality score if ads and marketing with Adwords. Anyway I am adding this RSS to my email and could look out for much more of your respective fascinating content. Ensure that you update this again very soon..

  8. Thank you for this very useful information. I found it quite interesting. Will definately keep close track of these pages. Great blog post. Youve gained a totally new reader. Please continue this awesome work and I anticipate see more of your superb articles. Thanks a great deal!

  9. hi ,

    solution over “class Zend not found” ,

    Instead of : Zend::dump($items);
    used : Zend_Debug::dump($items);

  10. Rss Dofollow link…

    [...]Getting an RSS feed with the Zend framework 0.1.1. / Stoyan’s phpied.com[...]…

  11. There are several ways to read RSS feed in PHP, but this one is surely one of the easiest.

    channel->item as $entry) {
    echo “link’ title=’$entry->title’>” . $entry->title . “”;
    }

    ?>

    Source:
    http://phphelp.co/2012/04/23/how-to-read-rss-feed-in-php/
    OR
    http://addr.pk/a0401

  12. fotografia ślubna

    fantastic issues altogether, you simply received a emblem new reader.
    What could you suggest in regards to your submit that you made
    a few days in the past? Any positive? fotografia ślubna

  13. Howdy, I do think your site might be having browser compatibility
    problems. When I look at your web site in Safari, it looks fine however,
    if opening in Internet Explorer, it has some overlapping issues.
    I simply wanted to provide you with a quick heads up!
    Apart from that, fantastic site!

  14. You really make it seem so easy with your presentation but I in finding
    this topic to be really one thing that I believe I would by no
    means understand. It seems too complex and very broad for me.
    I’m having a look forward in your next put up,
    I’ll attempt to get the hang of it!

Leave a Reply