Jump to content

Explode Help


stormx

Recommended Posts

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?

 

Link to comment
https://forums.phpfreaks.com/topic/151490-explode-help/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/151490-explode-help/#findComment-795661
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.