-4

I have this output:

<?xml version="1.0" encoding="UTF-8"?>
  <root>
    <disc>SVD1679354</disc>
    <cut>18349570</cut>
    <previewaac>http://api.7digital.com/1.2/track/preview?trackid=18349570&amp;oauth_consumer_key=7dadeprwudk7&amp;country=GB</previewaac>
    <previewmp3>http://api.7digital.com/1.2/track/preview?trackid=18349570&amp;oauth_consumer_key=7dadeprwudk7&amp;country=GB</previewmp3>
    <downloadlink></downloadlink>
    <codec></codec>
  </root>

I want this string output to be read in key value pair so that I can directly read a particular key to get its value.

The output is stored in string but the string represents an xml.

sashkello
  • 17,306
  • 24
  • 81
  • 109
user2118095
  • 763
  • 1
  • 7
  • 13

1 Answers1

0

use simplexml to access XML:

$xml = simplexml_load_string($x); // assume XML in $x
echo $xml->cut[0]; // access first <cut> node directly

more on this: http://www.php.net/manual/en/book.simplexml.php
of course, you can transform XML into an array with these functions, too

michi
  • 6,565
  • 4
  • 33
  • 56