SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Wizard mPeror's Avatar
    Join Date
    Mar 2005
    Location
    Saudi Arabia
    Posts
    1,724
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Quick feed parsin question

    Hi,

    I'm trying to parse this feed to get images from each post. I have no idea how to get the stuff between the <content:encoded> tags.

    When I try fetching the feed this way:
    Code PHP:
    $feed_data = file_get_contents($feed_url);
    if(!$feed_data) die('fetch failed, check feed URL');
    $feed = simplexml_load_string($feed_data);
    I get back an array with the "title", "link", "comments", "pubDate", "category", "guid" and "description. The content I'm looking for isn't even there.

    Any idea how I can get to it?

    Your help is much appreciated

  2. #2
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    simplexml_load_string($feed_data, 'SimpleXMLElement', LIBXML_NOCDATA);
    http://www.google.com/search?q=simplexml+cdata
    Cross browser css bugs

    Dan Schulz you will be missed

  3. #3
    SitePoint Wizard mPeror's Avatar
    Join Date
    Mar 2005
    Location
    Saudi Arabia
    Posts
    1,724
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks SoulScratch for the quick response.

    I had no idea it was an issue with CDATA (I'm new to feed parsing), but even after adding those additional parameters, I still don't get the contents within the feeds. I'm trying to get the first image from each post to be specific.

  4. #4
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is the output/source of your print_r/var_dump of that?
    Cross browser css bugs

    Dan Schulz you will be missed

  5. #5
    SitePoint Wizard mPeror's Avatar
    Join Date
    Mar 2005
    Location
    Saudi Arabia
    Posts
    1,724
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the print_r of the data:

    Code PHP:
    SimpleXMLElement Object ( [@attributes] => Array ( [version] => 2.0 ) [channel] => SimpleXMLElement Object ( [title] => Street Kings Arabia [link] => [url]http://content.streetkingsarabia.com[/url] [description] => Entertaiment section [lastBuildDate] => Wed, 24 Jun 2009 14:18:32 +0000 [generator] => [url]http://wordpress.org/?v=2.8[/url] [language] => en [item] => Array ( [0] => SimpleXMLElement Object ( [title] => test [link] => [url]http://feedproxy.google.com/~r/StreetKingsArabia/~3/gc2Xp7fn9ug/[/url] [comments] => [url]http://content.streetkingsarabia.com/?p=284#comments[/url] [pubDate] => Wed, 24 Jun 2009 14:17:03 +0000 [category] => Celebrity Videos [guid] => [url]http://content.streetkingsarabia.com/?p=284[/url] [description] => Share This! ) [1] => SimpleXMLElement Object ( [title] => Masarati [link] => [url]http://feedproxy.google.com/~r/StreetKingsArabia/~3/ITg3T_dVHyE/[/url] [comments] => [url]http://content.streetkingsarabia.com/?p=241#comments[/url] [pubDate] => Tue, 23 Jun 2009 07:44:44 +0000 [category] => 360 Degrees [guid] => [url]http://content.streetkingsarabia.com/?p=241[/url] [description] => SimpleXMLElement Object ( ) ) [2] => SimpleXMLElement Object ( [title] => Amal Hjazi – Exclusive interview! [link] => [url]http://feedproxy.google.com/~r/StreetKingsArabia/~3/mbGmF2YSH2o/[/url] [comments] => [url]http://content.streetkingsarabia.com/?p=232#comments[/url] [pubDate] => Tue, 23 Jun 2009 07:06:56 +0000 [category] => 360 Degrees [guid] => [url]http://content.streetkingsarabia.com/?p=232[/url] [description] => Share This! ) [3] => SimpleXMLElement Object ( [title] => Famous Car Designers [link] => [url]http://feedproxy.google.com/~r/StreetKingsArabia/~3/lpuIjxL9CqQ/[/url] [comments] => [url]http://content.streetkingsarabia.com/?p=207#comments[/url] [pubDate] => Mon, 22 Jun 2009 21:06:43 +0000 [category] => Industry Profiles [guid] => [url]http://content.streetkingsarabia.com/?p=207[/url] [description] => Famous car designers have been around just about as long as cars. What once started as a simple and functional process of designing a vehicle that would work to get people from one place to another has now evolved into a world of luxury, customization, and the use of vehicles as a hobby and not [...] ) [4] => SimpleXMLElement Object ( [title] => The world fastest car is… [link] => [url]http://feedproxy.google.com/~r/StreetKingsArabia/~3/TdUFHvP5Oa8/[/url] [comments] => [url]http://content.streetkingsarabia.com/?p=209#comments[/url] [pubDate] => Mon, 22 Jun 2009 20:45:16 +0000 [category] => Latest & Greatest [guid] => [url]http://content.streetkingsarabia.com/?p=209[/url] [description] => Finding out what’s the world fastest car is akin to figuring out who, amongst your friends, is the best Need For Speed player on PS3– everyone claims they’re the best, and are readily prepped with an arsenal of victories to validate their claim, and a number of extenuating circumstances to explain for any losses. A simple [...] ) [5] => SimpleXMLElement Object ( [title] => Most Successful Car Brand- And Why You Should Own One [link] => [url]http://feedproxy.google.com/~r/StreetKingsArabia/~3/-XyTXorQymk/[/url] [comments] => [url]http://content.streetkingsarabia.com/?p=200#comments[/url] [pubDate] => Mon, 22 Jun 2009 14:50:32 +0000 [category] => Latest & Greatest [guid] => [url]http://content.streetkingsarabia.com/?p=200[/url] [description] => It’s no surprise that the race to create the most successful car brand is a tight one. Among the many varieties of cars and brands out there, two are vying for the top spot in the auto history books as the most successful car brand in the world. As it stands, Toyota is leading the [...] ) [6] => SimpleXMLElement Object ( [title] => Max Mosley Career [link] => [url]http://feedproxy.google.com/~r/StreetKingsArabia/~3/JiVvcmfKZ2I/[/url] [comments] => [url]http://content.streetkingsarabia.com/?p=195#comments[/url] [pubDate] => Mon, 22 Jun 2009 14:35:43 +0000 [category] => Industry Profiles [guid] => [url]http://content.streetkingsarabia.com/?p=195[/url] [description] => Originally born Max Rufus Mosley on April 13, 1940, Max Mosley is the president of the FIA. This is a nonprofit association that represents motoring organizations and car enthusiasts around the world. It is also the governing body for Formula One racing and other motor sports that are internationally based. Max Mosley was an amateur [...] ) [7] => SimpleXMLElement Object ( [title] => Michael Schumacher Career- Formula 1’s Best [link] => [url]http://feedproxy.google.com/~r/StreetKingsArabia/~3/rPQB1oKoIBM/[/url] [comments] => [url]http://content.streetkingsarabia.com/?p=190#comments[/url] [pubDate] => Mon, 22 Jun 2009 13:50:25 +0000 [category] => Industry Profiles [guid] => [url]http://content.streetkingsarabia.com/?p=190[/url] [description] => Michael Schumacher was born in 1969 in Germany. He is a former seven-time world champion and Formula One driver that now focuses on advising and test driving for Ferrari. According to Formula One’s official website, based on statistics alone he is the greatest driver that the sport of Formula One racing has ever seen. He [...] ) [8] => SimpleXMLElement Object ( [title] => Top 10: 2009 Detroit Concept Car Reveals [link] => [url]http://feedproxy.google.com/~r/StreetKingsArabia/~3/Cmy5xlvdhEc/[/url] [comments] => [url]http://content.streetkingsarabia.com/?p=177#comments[/url] [pubDate] => Mon, 22 Jun 2009 12:33:38 +0000 [category] => Top 10's [guid] => [url]http://content.streetkingsarabia.com/?p=177[/url] [description] => By Thomas Bey – AskMen.com Automotive Correspondent A palatable sense of gloom hung over the 2009 North American International Auto Show in Detroit. Conspicuously absent were Ferrari, Land Rover, Porsche, and Rolls-Royce. Even Mitsubishi, Nissan and Suzuki made like the Detroit Lions and failed to perform. However, was the glass of Stroh’s half empty or half [...] ) [9] => SimpleXMLElement Object ( [title] => Top 10: Badass Movie Cars [link] => [url]http://feedproxy.google.com/~r/StreetKingsArabia/~3/jmvO9BQTWpw/[/url] [comments] => [url]http://content.streetkingsarabia.com/?p=161#comments[/url] [pubDate] => Mon, 22 Jun 2009 12:02:13 +0000 [category] => Top 10's [guid] => [url]http://content.streetkingsarabia.com/?p=161[/url] [description] => By Thomas Bey – AskMen.com Automotive Correspondent As long you’ve been going to the movies, you’ve seen gratuitous shots of these badass movie cars. You know they’re fake, but you still want to get your hands on them. Better still, the thought of you and your girlfriend getting your hands on them would be a helluva [...] ) [10] => SimpleXMLElement Object ( [title] => Top 10: All-Time Italian Cars [link] => [url]http://feedproxy.google.com/~r/StreetKingsArabia/~3/94b2yVJIAj0/[/url] [comments] => [url]http://content.streetkingsarabia.com/?p=148#comments[/url] [pubDate] => Mon, 22 Jun 2009 11:04:53 +0000 [category] => Top 10's [guid] => [url]http://content.streetkingsarabia.com/?p=148[/url] [description] => By Thomas Bey – AskMen.com Automotive Correspondent Like any good Italian opera, the Italian auto industry is distinguished by its passion, triumph and tragedy. The players’ performances frequently leave aficionados in tears — often out of joy, but not always. On the more positive side, here’s a look at the top 10 all-time Italian cars. Like similar [...] ) [11] => SimpleXMLElement Object ( [title] => Car Shows in the Middle East- Plenty to See [link] => [url]http://feedproxy.google.com/~r/StreetKingsArabia/~3/GC0wBhVz0KI/[/url] [comments] => [url]http://content.streetkingsarabia.com/?p=141#comments[/url] [pubDate] => Mon, 22 Jun 2009 09:55:39 +0000 [category] => Auto Shows [guid] => [url]http://content.streetkingsarabia.com/?p=141[/url] [description] => December of this year holds in store the 10th annual Middle East International Motor Show, which is currently called the Dubai International Motor Show. This is the one largest automotive event in the Middle East, and has been put on once every two years since 2007 brought in over 100,000 visitors from all over the [...] ) [12] => SimpleXMLElement Object ( [title] => Aston Martin One-77- Things to Know [link] => [url]http://feedproxy.google.com/~r/StreetKingsArabia/~3/OO2bG_kPKD8/[/url] [comments] => [url]http://content.streetkingsarabia.com/?p=133#comments[/url] [pubDate] => Mon, 22 Jun 2009 09:08:23 +0000 [category] => Latest & Greatest [guid] => [url]http://content.streetkingsarabia.com/?p=133[/url] [description] => The newest and hottest of one of the top luxury car manufacturers is the Aston Martin One-77. As its name clearly states, this car is scheduled to produce only 77 units, and starts at a fair price of $1 million EU. This car is the first Aston Martin in many years that is a truly [...] ) [13] => SimpleXMLElement Object ( [title] => Andy Green, Fastest Driver in the World? [link] => [url]http://feedproxy.google.com/~r/StreetKingsArabia/~3/PRmxxFJ4k-Q/[/url] [comments] => [url]http://content.streetkingsarabia.com/?p=123#comments[/url] [pubDate] => Mon, 22 Jun 2009 08:00:46 +0000 [category] => Industry Profiles [guid] => [url]http://content.streetkingsarabia.com/?p=123[/url] [description] => According to technicality, the fastest driver in the world is the one who currently holds the land speed record. This is the fastest speed achieved by any wheeled vehicle on land. The holder of this record is the ThrustSCC, a twin turbo-fan powered car that went more than 763 mph, driven by Andy Green. Therefore, [...] ) [14] => SimpleXMLElement Object ( [title] => Background on Mercedes Benz [link] => [url]http://feedproxy.google.com/~r/StreetKingsArabia/~3/E7UXitXn-jk/[/url] [comments] => [url]http://content.streetkingsarabia.com/?p=118#comments[/url] [pubDate] => Mon, 22 Jun 2009 07:28:53 +0000 [category] => The Inside Scoop [guid] => [url]http://content.streetkingsarabia.com/?p=118[/url] [description] => Mercedes-Benz is actually started as two separate companies in 1883 and 1890. First, Karl Benz founded Benz & Cie., and then Gottlieb Daimler followed suit with Daimler-Motoren-Gesellschaft or DMG. Each company at entity called their own trademark for publicity and distinctive purposes. Starting out, Benz and Daimler used their own names to develop some credibility, [...] ) [15] => SimpleXMLElement Object ( [title] => Background on Lamborghini [link] => [url]http://feedproxy.google.com/~r/StreetKingsArabia/~3/J2TzXeBWmTk/[/url] [comments] => [url]http://content.streetkingsarabia.com/?p=104#comments[/url] [pubDate] => Mon, 22 Jun 2009 07:16:36 +0000 [category] => The Inside Scoop [guid] => [url]http://content.streetkingsarabia.com/?p=104[/url] [description] => Lamborghini, more formally known as Automobili Lamborghini S.p.A., is an Italian auto manufacturer that prides itself in top-rate sports cars and only the best designs and styles. It was founded in 1963 by one Ferruccio Lamborghini, who started out owning a tractor factory. He had always manufactured tractors, but enjoyed driving sports cars and had [...] ) [16] => SimpleXMLElement Object ( [title] => Background on BMW [link] => [url]http://feedproxy.google.com/~r/StreetKingsArabia/~3/5d2Hq1kwwMg/[/url] [comments] => [url]http://content.streetkingsarabia.com/?p=99#comments[/url] [pubDate] => Sun, 21 Jun 2009 14:43:16 +0000 [category] => The Inside Scoop [guid] => [url]http://content.streetkingsarabia.com/?p=99[/url] [description] => Bayerische Motoren Werke AG, better known as BMW, is a German automobile manufacturer that was created in 1916. The BMW brand is well known for performance and luxury vehicles of all kinds. It also owns and produces the MINI brand and is the parent company to Rolls-Royce. The company originally worked with aircraft engine production, [...] ) [17] => SimpleXMLElement Object ( [title] => Background on Ferrari [link] => [url]http://feedproxy.google.com/~r/StreetKingsArabia/~3/rJTQDY5eeeU/[/url] [comments] => [url]http://content.streetkingsarabia.com/?p=88#comments[/url] [pubDate] => Sun, 21 Jun 2009 09:32:34 +0000 [category] => The Inside Scoop [guid] => [url]http://content.streetkingsarabia.com/?p=88[/url] [description] => Ferrari was founded in 1947 by Enzo Ferrari, and remains a leader in the sports car industry to this day. Ferrari started off with the 125 Sport, which had a 1.5 liter V-12 engine. The founder, while pleased with his creations, was less than pleased with his original customer base, most of whom were buying [...] ) ) ) )

  6. #6
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It may be because of the namespaces being used, try reading through all of http://blog.stuartherbert.com/php/20...rse-rss-feeds/ and trying what he did.
    Cross browser css bugs

    Dan Schulz you will be missed

  7. #7
    SitePoint Wizard mPeror's Avatar
    Join Date
    Mar 2005
    Location
    Saudi Arabia
    Posts
    1,724
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm getting confused here. I've used the same exact example in the link you've provided, except I've changed the 'content' namespace URL to my feed's URL, and removed the other name spaces, but I'm still getting almost the same results as before. Or at least I'm not getting the images within the CDATA.

    I admit I had no idea what was the modification I did since I didn't understand the tutorial well, so I'd really appreciate a bit more help.

  8. #8
    SitePoint Wizard mPeror's Avatar
    Join Date
    Mar 2005
    Location
    Saudi Arabia
    Posts
    1,724
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oooh I think I got it now. The only thing I was supposed to change in that code was the $blog_url variable. It works fine now! Thanks SoulScratch

    Why are we using namespaces from these urls though?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •