Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.