Jump to content

Recommended Posts

I'm trying to parse xml I loaded onto the page by simplexml_load_file and I'm using the following code to try to do this,

 

 

$resp = simplexml_load_file($request_url);
$shipping = $resp->rate[15]['total_charge'];
var_dump($shipping);
 
However I get NULL. Here is what the xml looks like when var dumped from $resp.
 
object(SimpleXMLElement)#1 (1) { ["rate"]=> object(SimpleXMLElement)#2 (1) { ["@attributes"]=> array(15) { ["weight"]=> string(3) "5.0" ["weight_unit"]=> string(2) "lb" ["zone"]=> string(1) "3" ["transit_time"]=> string(1) "1" ["transit_time_guaranteed"]=> string(5) "false" ["estimated_delivery_date"]=> string(10) "2013-07-31" ["base_charge"]=> string(5) "11.05" ["freight_charge"]=> string(5) "11.05" ["residential_address_charge"]=> string(4) "2.75" ["net_charge"]=> string(5) "13.80" ["fuel_surcharge_rate"]=> string(4) "17.3" ["fuel_surcharge"]=> string(4) "1.91" ["subtotal_charge"]=> string(5) "15.71" ["on_hst_charge"]=> string(4) "2.04" ["total_charge"]=> string(5) "17.75" } } }
 
and I'm trying to put this guy, ["total_charge"]=>string(5) "17.75" into it's own variable in php called $shipping so I can echo it out as $17.75.
 
Thanks for your time.
Link to comment
https://forums.phpfreaks.com/topic/280646-parsing-xml-var_dump-is-null/
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.