Monday, 9 February 2015

How to read XML output using PHP



I am trying to read an XML output listed below


SimpleXMLElement Object ( [merchant] => SimpleXMLElement Object ( [merchant-id] => SimpleXMLElement Object ( ) [merchant-name] => Snip-Its [merchant-category] => Hair [merchant-website] => www.snipits.com )



[store] => SimpleXMLElement Object
(
[store-id] => 173DFBB7-67F6-DE11-AD5B-0026B953348A
[store-name] => Heb
[store-number] => 0109
)

[coupon] => SimpleXMLElement Object
(
[coupon-id] => 385748
[coupon-address] => 14096 Memorial Drive
[coupon-city] => Houston
[coupon-state] => TX
)


)


using PHP script as follows but I get a value of '0'



foreach( $data->coupons as $mycoupon ) {
$address = $mycoupon->coupon->coupon-address;
//print_r($mycoupon);
}


So, Please help me to understand how to read the values of SimpleXMLElement Object and assign them to a local variable.


No comments:

Post a Comment