-1

I've such piece of code:

$xml=”<response>      
      <version>1.2</version>
      <merchant_id></merchant_id>
      <order_id> ORDER_123456</order_id>
      <amount>1.01</amount>
      <currency>UAH</currency>
      <description>Comment</description>
      <status>success</status>
      <code></code>
      <transaction_id>31</transaction_id>
      <pay_way>card</pay_way>
      <sender_phone>+3801234567890</sender_phone>
      <goods_id>1234</goods_id>
      <pays_count>5</pays_count>
</response>";

Could I parse it? How to do it? I had never work with XML. E.g how to take ?

sanatik
  • 33
  • 1
  • 2
  • 10

3 Answers3

2

You should use simplexml_load_string function.

Parse as follow:

echo simplexml_load_string($xml)->version;

There is plenty functions you could use have a look at the link above.

hakre
  • 193,403
  • 52
  • 435
  • 836
JTC
  • 3,344
  • 3
  • 28
  • 46
1

Try saving your XML to a file and use simplexml to parse it in php.

See tutorial here: http://blog.teamtreehouse.com/how-to-parse-xml-with-php5

0

You should use DomDocument. It is much more flexible and useful than SimpleXML.

Parse as follows:

$doc = new DOMDocument();
$doc->loadXML($xml);
$price = $doc->getElementsByTagName('amount');
$currency = $doc->getElementsByTagName('currency');
XaxD
  • 1,429
  • 14
  • 27