HaLo2FrEeEk Posted September 17, 2007 Share Posted September 17, 2007 I have an xml feed that is hosted on another site, which is an extension of my site. I don't want to host the feed on my site, but I want to display information from the feed on a page on my site. I need to parse out all the items from the feed xml, so I can get the individual informations out of it. I'm having a bit of trouble doing this though, I don't know why, my regex seems logical enough. This is the xml I'm trying to parse: <?xml version="1.0" encoding="utf-8"?> <rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0"> <channel> <title>Clan Infectionist</title> <itunes:subtitle>Clan Infectionist</itunes:subtitle> <link>http://claninfectionist.mypodcast.com/</link> <description>Welcome to the Ranks of The Infected Podcast.</description> <itunes:summary>Welcome to the Ranks of The Infected Podcast.</itunes:summary> <language>en</language> <copyright>© 2007 Clan Infectionist</copyright> <itunes:author>HaLo2FrEeEk</itunes:author> <itunes:owner> <itunes:name>HaLo2FrEeEk</itunes:name> <itunes:email>[email protected]</itunes:email> </itunes:owner> <itunes:image href="http://www.mypodcast.com/image-73924.jpg"/> <itunes:explicit>yes</itunes:explicit> <itunes:category text="Games & Hobbies"> <itunes:category text="Video Games"/> </itunes:category> <lastBuildDate>Sat, 01 Sep 2007 15:44:12 -0800</lastBuildDate> <docs>http://blogs.law.harvard.edu/tech/rss</docs> <generator>MyPodcast.com RSS generator v1.0</generator> <managingEditor>[email protected]</managingEditor> <webMaster>[email protected]</webMaster> <item> <title>The Beginning of...idk.</title> <itunes:subtitle>The Beginning of...idk.</itunes:subtitle> <description>Another retarded title, I seem to be full of those lately. It's ok, I'm sure you'll live. As for the podcast, good stuff in there, completely useless boring stuff, but good too; I just wanted to give you all something to masterbate...I mean...listen to, while I'm gone...yeah.</description> <itunes:summary>Another retarded title, I seem to be full of those lately. It's ok, I'm sure you'll live. As for the podcast, good stuff in there, completely useless boring stuff, but good too; I just wanted to give you all something to masterbate...I mean...listen to, while I'm gone...yeah.</itunes:summary> <itunes:author>HaLo2FrEeEk</itunes:author> <guid isPermaLink="true">http://claninfectionist.mypodcast.com/2007/09/The_Beginning_ofidk-38428.html</guid> <pubDate>Sat, 01 Sep 2007 15:44:12 -0800</pubDate> <enclosure url="http://www.mypodcast.com/fsaudio/claninfectionist_20070901_1544-75568.mp3" length="4082831" type="audio/mpeg"/> <itunes:duration>05:41</itunes:duration> <itunes:explicit>clean</itunes:explicit> </item> <item> <title>The End of The Beginning</title> <itunes:subtitle>The End of The Beginning</itunes:subtitle> <description>Yes...I know that made no sense, but that's how I roll. I'm that cool. This started of quite sad, actually, but events transpired to turn my moods in such a way that actually put the first real smile on my face in a quite a while. Enjoy. STOP READING THIS, LISTEN TO THE PODCAST!</description> <itunes:summary>Yes...I know that made no sense, but that's how I roll. I'm that cool. This started of quite sad, actually, but events transpired to turn my moods in such a way that actually put the first real smile on my face in a quite a while. Enjoy. STOP READING THIS, LISTEN TO THE PODCAST!</itunes:summary> <itunes:author>HaLo2FrEeEk</itunes:author> <guid isPermaLink="true">http://claninfectionist.mypodcast.com/2007/08/The_End_of_The_Beginning-37797.html</guid> <pubDate>Wed, 29 Aug 2007 04:50:41 -0800</pubDate> <enclosure url="http://www.mypodcast.com/fsaudio/claninfectionist_20070829_0450-73936.mp3" length="13415755" type="audio/mpeg"/> <itunes:duration>18:38</itunes:duration> <itunes:explicit>clean</itunes:explicit> </item> <item> <title>The "Finally an update" update</title> <itunes:subtitle>The "Finally an update" update</itunes:subtitle> <description>Yes, it is about time, but I make up for it by giving you a 13 minute podcast for you to enjoy. In it I describe our new movie, Heart of Revenge, I also whine just a little, and promote our general awesomeness. What can I say, it's what I do.</description> <itunes:summary>Yes, it is about time, but I make up for it by giving you a 13 minute podcast for you to enjoy. In it I describe our new movie, Heart of Revenge, I also whine just a little, and promote our general awesomeness. What can I say, it's what I do.</itunes:summary> <itunes:author>HaLo2FrEeEk</itunes:author> <guid isPermaLink="true">http://claninfectionist.mypodcast.com/2007/07/The_Finally_an_update_update-30924.html</guid> <pubDate>Fri, 27 Jul 2007 05:54:00 -0800</pubDate> <enclosure url="http://www.mypodcast.com/fsaudio/claninfectionist_20070727_0554-56141.mp3" length="10006149" type="audio/mpeg"/> <itunes:duration>13:54</itunes:duration> <itunes:explicit>clean</itunes:explicit> </item> <item> <title>HaLo2FrEeEk's last update</title> <itunes:subtitle>HaLo2FrEeEk's last update</itunes:subtitle> <description>well, not my last ever, but my last before I graduate. I won't go into too much detail here though, becuase then the podcast would be spoiled, and I heard that spoiled podcasts aren't very good, but I could have heard wrong...<img src="http://www.mypodcast.com/image-38562"></description> <itunes:summary>well, not my last ever, but my last before I graduate. I won't go into too much detail here though, becuase then the podcast would be spoiled, and I heard that spoiled podcasts aren't very good, but I could have heard wrong...</itunes:summary> <itunes:author>HaLo2FrEeEk</itunes:author> <guid isPermaLink="true">http://claninfectionist.mypodcast.com/2007/06/HaLo2FrEeEks_last_update-23191.html</guid> <pubDate>Sat, 16 Jun 2007 03:10:00 -0800</pubDate> <enclosure url="http://www.mypodcast.com/fsaudio/claninfectionist_20070616_0310-38561.mp3" length="4245835" type="audio/mpeg"/> <itunes:image href="http://www.mypodcast.com/image-38562"/> <itunes:duration>05:54</itunes:duration> <itunes:explicit>no</itunes:explicit> </item> <item> <title>Clan Infectionist's First Podcast</title> <itunes:subtitle>Clan Infectionist's First Podcast</itunes:subtitle> <description>That's right, we have a podcast now, ain't we cool...no...ok, go away. Anyways, I made this the same night I set up this podcast, unfortunately, I have no microphone, so I used my cell phone to record to wav format. It still sounds good though, my voice just sounds a little higher.<img src="http://www.mypodcast.com/image-36915"></description> <itunes:summary>That's right, we have a podcast now, ain't we cool...no...ok, go away. Anyways, I made this the same night I set up this podcast, unfortunately, I have no microphone, so I used my cell phone to record to wav format. It still sounds good though, my voice just sounds a little higher.</itunes:summary> <itunes:author>HaLo2FrEeEk</itunes:author> <guid isPermaLink="true">http://claninfectionist.mypodcast.com/2007/06/Clan_Infectionists_First_Podcast-22365.html</guid> <pubDate>Tue, 12 Jun 2007 02:59:00 -0800</pubDate> <enclosure url="http://www.mypodcast.com/fsaudio/claninfectionist_20070612_0259-36912.mp3" length="5750802" type="audio/mpeg"/> <itunes:image href="http://www.mypodcast.com/image-36915"/> <itunes:keywords>halo, infection, halo2, clan, halo2freeek, infectionist</itunes:keywords> <itunes:duration>08:00</itunes:duration> <itunes:explicit>clean</itunes:explicit> </item> </channel> </rss> I need to get all of these out: <item> <title>Clan Infectionist's First Podcast</title> <itunes:subtitle>Clan Infectionist's First Podcast</itunes:subtitle> <description>That's right, we have a podcast now, ain't we cool...no...ok, go away. Anyways, I made this the same night I set up this podcast, unfortunately, I have no microphone, so I used my cell phone to record to wav format. It still sounds good though, my voice just sounds a little higher.<img src="http://www.mypodcast.com/image-36915"></description> <itunes:summary>That's right, we have a podcast now, ain't we cool...no...ok, go away. Anyways, I made this the same night I set up this podcast, unfortunately, I have no microphone, so I used my cell phone to record to wav format. It still sounds good though, my voice just sounds a little higher.</itunes:summary> <itunes:author>HaLo2FrEeEk</itunes:author> <guid isPermaLink="true">http://claninfectionist.mypodcast.com/2007/06/Clan_Infectionists_First_Podcast-22365.html</guid> <pubDate>Tue, 12 Jun 2007 02:59:00 -0800</pubDate> <enclosure url="http://www.mypodcast.com/fsaudio/claninfectionist_20070612_0259-36912.mp3" length="5750802" type="audio/mpeg"/> <itunes:image href="http://www.mypodcast.com/image-36915"/> <itunes:keywords>halo, infection, halo2, clan, halo2freeek, infectionist</itunes:keywords> <itunes:duration>08:00</itunes:duration> <itunes:explicit>clean</itunes:explicit> </item> This is my regex I'm trying to use: preg_match_all("#<item>(.+?)</item>#", $text, $matches); It isn't returning anything. Is there something I'm doing wrong? I'm trying to capture everything between <item> and </item>. Any help would be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/69657-solved-need-help-parsing-xml-feed/ Share on other sites More sharing options...
effigy Posted September 17, 2007 Share Posted September 17, 2007 A . does not match a new line unless the /s modifier is used (or, in your case, #s). If you need to alter the data further, consider XSLT. Link to comment https://forums.phpfreaks.com/topic/69657-solved-need-help-parsing-xml-feed/#findComment-350015 Share on other sites More sharing options...
HaLo2FrEeEk Posted September 18, 2007 Author Share Posted September 18, 2007 So just change my regex to this: preg_match_all("#<item>(.+?)</item>#s", $text, $matches); I'm sorry, I can't grasp the concept of regex's at all. Link to comment https://forums.phpfreaks.com/topic/69657-solved-need-help-parsing-xml-feed/#findComment-350363 Share on other sites More sharing options...
effigy Posted September 18, 2007 Share Posted September 18, 2007 Well, did it work? A regular expression must consist of delimiters and a pattern; modifiers are optional. The format is: delimiter pattern delimiter modifiers Your delimiter is #. Link to comment https://forums.phpfreaks.com/topic/69657-solved-need-help-parsing-xml-feed/#findComment-350426 Share on other sites More sharing options...
HaLo2FrEeEk Posted September 19, 2007 Author Share Posted September 19, 2007 Well that much I did know, I just can't ever figure out how to put stuff, some things are way weird. Anyways, I did it, but I had a little bit of help, I used RegexBuddy. I still had to write the regex, but it just showed me if it worked in real time instead of constantly re uploading. I used this: %<info>(.+?)</info>%is It works perfectly. Thank you for your help. Link to comment https://forums.phpfreaks.com/topic/69657-solved-need-help-parsing-xml-feed/#findComment-350858 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.