stormx Posted March 28, 2009 Share Posted March 28, 2009 Hello, I wish to explode an XML file like the following: <Response> <ServiceNumber>234567891</ServiceNumber> <ContractDetails> <ContractStartDate>2002-01-01</ContractStartDate> <ContractPeriod>12 Months</ContractPeriod> <ContractEndDate>2012-01-01</ContractEndDate> </ContractDetails> <PlanDetails> <PlanName>XXXX</PlanName> <LineSpeed>XXXX</LineSpeed> <PeakTimeDownloadInMB>1000</PeakTimeDownloadInMB> <OffpeakTimeDownloadInMB>2000</OffpeakTimeDownloadInMB> <PeakShaping>NO</PeakShaping> <OffpeakShaping>NO</OffpeakShaping> <PlanPrice>$10.00</PlanPrice> <ExtraDownloadPerGB>$1.00</ExtraDownloadPerGB> </PlanDetails> <IPAddress>255.255.255.0</IPAddress> </Response> I've tried the PHP Explode function, but it just seems really weird applying it to that code, is their any simpler way of exploding it? Quote Link to comment https://forums.phpfreaks.com/topic/151490-explode-help/ Share on other sites More sharing options...
Philip Posted March 28, 2009 Share Posted March 28, 2009 Have you thought about using SimpleXML - good for smaller files Otherwise... take a look at http://www.codehelp.co.uk/php/xmlparse1.php Quote Link to comment https://forums.phpfreaks.com/topic/151490-explode-help/#findComment-795660 Share on other sites More sharing options...
stormx Posted March 28, 2009 Author Share Posted March 28, 2009 Well the XML file isn't really an XML file at all, its just a PHP file obtaining stuff from a database and exporting it as plain text. If I were to write an explode function how would I go about doing this? function getusage($username, $password, $type) { $link = "http://domain.com/usagemeter_xml.php?$username,$password"; $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_URL, $link); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $str = curl_exec($ch); $tmp_explode = explode("<", $str); $data = array(); foreach($tmp_explode as $line){ $tmp_line = explode(">", $line); $data[$tmp_line[0]] = $tmp_line[1]; } //end it return $data[$type]; } Would this work if I worked on it? Quote Link to comment https://forums.phpfreaks.com/topic/151490-explode-help/#findComment-795661 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.