Getting an RSS feed with the Zend framework 0.1.1.
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.
- Get the zip/tar.gz from the framework site
- Uncompress somewhere. You'll see 4 folders in the package -
demos(some example scripts),documentation,incubator(pre-relase libraries) andlibrary(the real thing) - 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.
// 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.
This entry was posted on Sunday, March 5th, 2006 and is filed under Zend framework. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Get notification for future posts: follow me on Twitter or subscribe to my RSS feed

March 7th, 2006 at 1:51 am
[...] А вот и первый пример того, как оно работает с новостными фидами. Вроде не сложно совсем, вот только по моему они наступили с Zend_Feed на грабельки с кодировками, хотя я могу ошибаться… Посмотрим в будущем, когда выйдет версия 1.0. [...]
March 8th, 2006 at 10:57 am
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….
March 8th, 2006 at 1:41 pm
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 …
May 5th, 2006 at 6:37 am
very nice intro! muchas gracias
September 15th, 2008 at 2:40 pm
this script show error on run
class ‘Zend’ not found in /home/eugene/seo_project/music_rss/rss_music.php on Zend::dump($items);