Maryadi Poipo
Maryadi Poipo

Reputation: 1478

How to get xml response by openin url in PHP

I'm opening an url using my browser and got an xml response like this :

<Error>
<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
<Key>cvs/1142</Key>
<RequestId>1F3326A4AAAD2459</RequestId>
<HostId>
0AL/FcwMI2ePg0WU1Cako5mDpFsxKraqXigdxnrKItD2Mf5KX91UpLIEunj2DrU4GMz/ukQQAuw=
</HostId>
</Error>

In PHP, I'm using file_get_contents($myURL), the problem is I can't get the xml response like what I got from the browser. So How to achieve this ? I just want to get the "<Message>The specified key does not exist.</Message>"

Thanks in advance

Upvotes: 1

Views: 81

Answers (1)

Slava
Slava

Reputation: 938

You can try this or this for transform xml to array. And then you can get the message by key: $arr['message']

Upvotes: 1

Related Questions