unistake Posted July 24, 2009 Share Posted July 24, 2009 Hi all, I am trying to extract some information from a website, however need some help in to how to put the xml files in to php variables. I understand just about this code! <?php $data = file_get_contents("http://www.bluesq.com/bluesq_php/cubs/cubs.php?action=getpage&thepage=385.xml"); ?> However the data in the page above is repeated with different values like this.. <BSQCUBS Version="0.04" Date="Thu Jul 23 16:00:39 BST 2009" MachineDate="Thu, 23 Jul 2009 16:00:39 +0100"> − <Class class_id="385"> <Title>Football Matches</Title> − <Type type_id="5143" type_minbet="0" type_maxbet="0"> <Title>UEFA Europa League</Title> − <Event start_time="2009-07-23 16:00:00" ev_id="1948510" ev_minbet="0.01" ev_maxbet="1000.0" racetype="" tracktype="" handicap=" " trifecta=" " eligibility="" distance="" going="0" class="0"> <Description>Karabakh Agdam v Rosenborg</Description> − <Market mkt_typ="Win/Draw/Win" lp_avail="Y" sp_avail="N" mkt_id="3054130"> − <Occurrence bet_id="23101981" lp_num="1" lp_den="4" decimal="1.25" oc_minbet="0.5" oc_maxbet="500.0"> <Description>Rosenborg</Description> </Occurrence> − <Occurrence bet_id="23101980" lp_num="15" lp_den="4" decimal="4.75" oc_minbet="0.5" oc_maxbet="80.0"> <Description>Draw</Description> </Occurrence> − <Occurrence bet_id="23101979" lp_num="11" lp_den="1" decimal="12" oc_minbet="0.5" oc_maxbet="230.0"> <Description>Karabakh Agdam</Description> </Occurrence> </Market> There are several other 'Markets' in the xml file however I would like to extract the above so that I can have something in the order of... $game_date = EventStartTime; $homeodds = EventDecimals; etc If anyone knows how to do this it would be much appreciated, also any links for learning this sort of extraction would be great. Thanks Link to comment https://forums.phpfreaks.com/topic/167262-solved-php-variables-from-xml/ Share on other sites More sharing options...
haku Posted July 24, 2009 Share Posted July 24, 2009 You need to parse the XML. Fortunately, there is a nice tutorial on parsing XML on this very site! http://www.phpfreaks.com/tutorial/handling-xml-data Link to comment https://forums.phpfreaks.com/topic/167262-solved-php-variables-from-xml/#findComment-881890 Share on other sites More sharing options...
dzelenika Posted July 24, 2009 Share Posted July 24, 2009 use simplexml, it is easy: $xml = new SimpleXMLElement(file_get_contents(("http://www.bluesq.com/bluesq_php/cubs/cubs.php?action=getpage&thepage=385.xml")); echo $xml->class->type->event['start_time']; Link to comment https://forums.phpfreaks.com/topic/167262-solved-php-variables-from-xml/#findComment-881892 Share on other sites More sharing options...
rhodesa Posted July 24, 2009 Share Posted July 24, 2009 <?php $xml = simplexml_load_file('http://www.bluesq.com/bluesq_php/cubs/cubs.php?action=getpage&thepage=385.xml'); foreach($xml->Class->Type as $type){ echo $type->Event->Description . '<br />'; } ?> Link to comment https://forums.phpfreaks.com/topic/167262-solved-php-variables-from-xml/#findComment-881917 Share on other sites More sharing options...
unistake Posted July 24, 2009 Author Share Posted July 24, 2009 Thanks for all your help, fantastic replies. Cheers! Link to comment https://forums.phpfreaks.com/topic/167262-solved-php-variables-from-xml/#findComment-882129 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.