Web Design Forums

PHP

Have questions about PHP? Ask them here and our experts will assist you before you know it! You can also find help in the documentation at PHP.net.

Importing info from xml feed into php



Site of the Month Nominations
ENTER YOUR SITE NOW!

Reply
 
LinkBack Thread Tools
Old June 13 '09, 02:03 PM (#1)
ash.kendall is offline
WDF Member
 
ash.kendall's Avatar
 
Join Date: August 2006
Location: Sheffield, UK
Posts: 24
ash.kendall is an unknown quantity at this point
Importing info from xml feed into php

Hi guys,

I'm trying to build an web application that will generate a schedule for cinema times. Basically, the showtimes for a film are taken, along with the film length, and a table is made showing all the films together so you can see where they overlap, when they finish etc.

So they don't have to be entered manually I've got the listings from the Cineworld site and want (for now) the full guide to be shown. Problem being, I haven't got a clue how to use it!

The link given by Cineworld is here. I'm wanting to import the info from listings.xml so I can provide a list of cinemas and then the films and showtimes from that cinema. I'm hoping that I can import some info from the all-performances.xml file too as that contains info (like the run-time) of the films.

So, any suggestions?! I've searched and found a few guides that are aimed at RSS news feeds but none of these look like they'll apply in this case.

Any help is appreciated!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 13 '09, 03:39 PM (#2)
mlseim is offline
WDF Staff
 
mlseim's Avatar
 
Join Date: April 2004
Location: Cottage Grove, Minnesota
Posts: 3,401
mlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud of
Describe how you plan on displaying the information.
I mention this because the XML files are large and there are many different movie times.

How much of the information are you planning on displaying? ...
and better yet, show us an example web page that you're working on
with some fake info entered, so we an see how your final thing is supposed
to look. This is important because of the different ways to read the XML file.

Give us a link to your URL.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 13 '09, 04:02 PM (#3)
ash.kendall is offline
WDF Member
 
ash.kendall's Avatar
 
Join Date: August 2006
Location: Sheffield, UK
Posts: 24
ash.kendall is an unknown quantity at this point
I've had a few problems deciding on how the information will be displayed. I'd like to be a sort of time-table appearance, the hours of the day across the top and blocks displaying the time the film is showing.

I've not actually built anything yet because I'm not sure how I'm going to get the info in the site. I was hoping that I could start once I figured a way of getting the info I want from the XML file into a page. Then I could manipulate it.

The plan was to select the preferred cinema (e.g. Sheffield) and the date you would like to see the schedule for, and then the films and times for them would be displayed in the timetable format.

I'm basically just looking for a way to get the info from the XML files into a php array. I've just found a site that does something very similar here.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 13 '09, 04:06 PM (#4)
Dorky is offline
Freelance
 
Dorky's Avatar
 
Join Date: June 2009
Location: Destin Florida
Posts: 905
Dorky will become famous soon enough
just wanted to mention before getting started that on the example link given the details vs dates time doesnt work on my setup.


ubuntu jaunty / firefox3
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 14 '09, 06:08 AM (#5)
imagn is offline
WDF Regular
 
imagn's Avatar
 
Join Date: July 2007
Location: Los Angeles
Posts: 156
imagn will become famous soon enough
Import the data into MySQL (equivalent) using the DOM library. This is by no means a complete example but...

$file_name = "feed.xml";
$doc = new DOMDocument();
$doc->load($file_name);
$toplevel = $doc->getElementsByTagName("a");

// NEEDS TO LOOP THROUGH EACH ELEMENT AND GRAB RESPECTIVE VALUE
foreach( $toplevel as $a) {
$node_1_var = $a->getElementsByTagName("b");
$node_1_val = $node_1_var->item(0)->nodeValue;
// ect....
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 14 '09, 10:46 PM (#6)
filburt1 is offline
bored
 
filburt1's Avatar
 
Join Date: July 2002
Location: Maryland, US
Posts: 11,785
filburt1 is a name known to allfilburt1 is a name known to allfilburt1 is a name known to allfilburt1 is a name known to allfilburt1 is a name known to allfilburt1 is a name known to all
I was about to suggest the DOM library too (annoyingly, domxml in PHP 4). Essentially it's identical to the DOM in Javascript, so if you've used it there, it should be pretty easy in PHP.

If you want to quickly (at least, few lines of code) retrieve certain nodes from XML, you might want to use XPath, also supported by the PHP DOM library.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 18 '09, 03:08 AM (#7)
Danny[MLWA] is offline
WDF Regular
 
Danny[MLWA]'s Avatar
 
Join Date: June 2009
Location: Goldsboro, North Carolina, USA
Posts: 109
Danny[MLWA] is on a distinguished road
I've seen problems with using DOM -- and cvsimport as well. Basically if the RSS feed isn't perfect it errors out. For that I use my own script... Its not perfect but I use Curl to grab the raw text then use my own parser through php to sort and sift the data... If you tell it to only look for certain tags from there and to explode the document into those fields, it works with extreme consistantcy even if they have errors in thier rss as the script won't care.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 18 '09, 05:49 PM (#8)
filburt1 is offline
bored
 
filburt1's Avatar
 
Join Date: July 2002
Location: Maryland, US
Posts: 11,785
filburt1 is a name known to allfilburt1 is a name known to allfilburt1 is a name known to allfilburt1 is a name known to allfilburt1 is a name known to allfilburt1 is a name known to all
If the RSS feed isn't well-formed XML you'll have a hell of a time trying to get anything out of it.

You can try passing it through something like Tidy to fix it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 18 '09, 06:02 PM (#9)
Danny[MLWA] is offline
WDF Regular
 
Danny[MLWA]'s Avatar
 
Join Date: June 2009
Location: Goldsboro, North Carolina, USA
Posts: 109
Danny[MLWA] is on a distinguished road
he he...

PHP Code:
$row explode('<channel>'$curled);
for (
$i=0;$i<count($row);$i++)
{
$title_a explode('<title>'$row[$i]);
$title explode('</title>'$title_a[1]);
// Use as $title[0]; and repeat for each data field you want to dump into the database =)

Been using that setup for RSS feeds and CVS imports for years.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

  Web Design Forums » Programming Help » PHP

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Top 21 PHP Programming mistakes thexchord PHP 19 June 18 '10 02:20 PM
The future of Web Design Forums.net filburt1 Announcements 128 January 30 '10 05:27 AM
PHP / XML - Please Help!! Lunarben PHP 6 April 1 '09 11:27 AM
How to run ExamXML from PHP to compare XML files. alapick PHP 1 April 29 '07 08:15 PM
Request for PHP and ASP Info lmarshall General Web Design Discussion 4 April 28 '03 03:05 PM

 
User Infomation
Your Avatar

Site Of The Month

Ticket Cake
Ticket Cake

Ticket Cake is a drupal based event ticketing platform. It features that ability to browse events and share them.

Nominate Your Site Now!

Advertisement
WolfCMS.org

Latest Articles
- by RickM
- by bfsog

Advertisement

Partner Links



All times are GMT -4. The time now is 02:45 AM.


WebDesignForums.net is Copyright © 2010 RikeMedia.

SEO by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163