Hey all....
I have a string response from the API , is XML response..
the response is as below
<?xml version="1.0"?><RatingServiceSelectionResponse><Response><TransactionReference><CustomerContext> Shipping</CustomerContext><XpciVersion>1.0001</XpciVersion></TransactionReference><ResponseStatusCode>1</ResponseStatusCode><ResponseStatusDescription>Success</ResponseStatusDescription></Response><RatedShipment><Service><Code>03</Code></Service><RatedShipmentWarning>Your invoice may vary from the displayed reference rates</RatedShipmentWarning><BillingWeight><UnitOfMeasurement><Code>LBS</Code></UnitOfMeasurement><Weight>36.0</Weight></BillingWeight><TransportationCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>31.14</MonetaryValue></TransportationCharges><ServiceOptionsCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>0.00</MonetaryValue></ServiceOptionsCharges><TotalCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>31.14</MonetaryValue></TotalCharges><GuaranteedDaysToDelivery></GuaranteedDaysToDelivery><ScheduledDeliveryTime></ScheduledDeliveryTime><RatedPackage><TransportationCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>31.14</MonetaryValue></TransportationCharges><ServiceOptionsCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>0.00</MonetaryValue></ServiceOptionsCharges><TotalCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>31.14</MonetaryValue></TotalCharges><Weight>36.0</Weight><BillingWeight><UnitOfMeasurement><Code>LBS</Code></UnitOfMeasurement><Weight>36.0</Weight></BillingWeight></RatedPackage></RatedShipment></RatingServiceSelectionResponse>
I wanted to save the value of
<TotalCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>31.14</MonetaryValue></TotalCharges>
the value of monetaryvalue ( that of TotalCharges array) field which is 31.14 .
I tried out the below regular-exp..
$str = $shipping->_xml_response;
$var = preg_match("/<TotalCharges><CurrencyCode>USD<\/CurrencyCode><MonetaryValue>(.*)<\/MonetaryValue>/",$str,$matches);
if($var == true){
echo $matches[0];}else echo "no match";
and the o/p from that is USD31.14USD31.14USD0.00USD31.14
But i want just 31.14(that may be different e'time) which is declared last(not the first 31.14,not the second 0.00 , but the last 31.14)....how can i do so??