XML
結果をフォーマットで返す Web サービスを使用しました。メソッドsimplexml_load_string()
を使用して、次のようなオブジェクトに変換しました。
$xml = simplexml_load_string($result[$webresult]);
以下は、 を使用した表示例
print_r($xml)
です。
SimpleXMLElement Object ( [record] => SimpleXMLElement Object ( [txnref] => 6113229211825720 [channel] => mastercard [amount] => 3000.00 [payment_date] => 8/17/2013 9:18:25 PM [payment_status] => successful [field_values] => SimpleXMLElement Object ( [field_values] => SimpleXMLElement Object ( [field] => Array ( [0] => SimpleXMLElement Object ( [names] => Frank [acct_desc] => False [acct_desc_order] => 0 [hidden] => False [defaultvalue] => SimpleXMLElement Object ( ) [xpath_field] => 0 ) [1] => SimpleXMLElement Object ( [amount] => 3000 [acct_desc] => False [acct_desc_order] => 0 [hidden] => False [defaultvalue] => SimpleXMLElement Object ( ) [xpath_field] => 0 ) [2] => SimpleXMLElement Object ( [currency] => NGN [acct_desc] => False [acct_desc_order] => 0 [hidden] => False [defaultvalue] => SimpleXMLElement Object ( ) [xpath_field] => 0 ) [3] => SimpleXMLElement Object ( [email_address] => chibuzo.henry@gmail.com [acct_desc] => False [acct_desc_order] => 0 [hidden] => False [defaultvalue] => SimpleXMLElement Object ( ) [xpath_field] => 0 ) [4] => SimpleXMLElement Object ( [phone_number] => 08035653468 [acct_desc] => False [acct_desc_order] => 0 [hidden] => False [defaultvalue] => SimpleXMLElement Object ( ) [xpath_field] => 0 ) [5] => SimpleXMLElement Object ( [merch_txnref] => 134 [acct_desc] => False [acct_desc_order] => 0 [hidden] => False [defaultvalue] => SimpleXMLElement Object ( ) [xpath_field] => 0 ) ) ) ) [payment_status_description] => Transaction Successful - Approved ) )
ただし、 object にアクセスしようとすると$xml
、次のようになります。
$xml->amount;
結果は返されません。オブジェクトのプロパティに正しくアクセスするにはどうすればよいですか?