andy1212 Posted July 30, 2013 Share Posted July 30, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/280646-parsing-xml-var_dump-is-null/ 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.