O'Reilly logo

Laravel Application Development Blueprints by Halil İbrahim Yılmaz, Arda Kılıçdağı

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Reading and parsing an external feed

We have the feed URLs and the titles on our server all categorized. Now all we have to do is to parse them and show them to the end user. There are some steps to follow for this:

  1. First, we need a method to parse external Atom feeds. Open your Str.php file located at app/lib/Support/ and add this method into the class:
    public static function parse_feed($url) { //First, we get our well-formatted external feed $feed = simplexml_load_file($url); //if cannot be found, or a parse/syntax error occurs, we return a blank array if(!count($feed)) { return array(); } else { //If found, we return the newest five <item>s in the <channel> $out = array(); $items = $feed->channel->item; for($i=0;$i<5;$i++) { $out[] = $items[$i]; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required