0

I am pulling a value from a xml using PHP's simpleXML. When I echo the value it is fine, however when I store the value in a PHP variable and then do some math with it or even echo it, it does not return anything. I var_dumped the $_SESSION in which I stored the value and it shows: ["shippingPrice"]=> object(SimpleXMLElement)#6 (1) { [0]=> string(4) "5.60" instead of diplaying just the 5.60 value.

How could I achieve this?

Here is my code:

$response = new SimpleXMLElement($result);
$shippingPrice = $response->Package->Postage->Rate;
    $_SESSION['shippingPrice'] = $shippingPrice;
echo $shippingPrice;
echo $_SESSION['shippingPrice'];

Both echos are empty.

Thanks

hakre
  • 193,403
  • 52
  • 435
  • 836
samyb8
  • 2,560
  • 10
  • 40
  • 68
  • Also you need to enable error logging because you can not store SimpleXMLElements inside session variables. However PHP will only tell you when you do error logging because when the session serialization is done (and fails), there is no output any longer. Only logging to file will work. Take care. – hakre Jun 13 '13 at 09:06

1 Answers1

3

Cast your SimpleXMLElement, e.g.

$shippingPrice = (float) $response->Package->Postage->Rate;

ExternalUse
  • 2,053
  • 2
  • 25
  • 37