Reputation: 11
Using CURL, I send an xml file to a server and receive a 200 response and reciprocal XML file from said server.
$response = curl_exec($session);
So far so good. If I do print_r($response)
I see that the url i need is indeed inside $response
.
The question i have is how do i parse it out? I try variations of the following but nothing seems to work:
$xml = new SimpleXMLElement($response);
Pointer in the right direction would be great.
Thanks!
Upvotes: 0
Views: 8812
Reputation: 1060
You need use the following structure:
$xml = new SimpleXMLElement($response);
echo $xml->movie[0]->plot;
//Or
$xml = simplexml_load_file($file, 'SimpleXMLElement', LIBXML_NOCDATA);
Where movie is a node from yor xml structure.
Upvotes: 1
Reputation: 3066
You need to set the right curl options. It looks like the header information is being included in the response data, which of course makes the response invalid XML. You can see the curl options here:
http://www.php.net/manual/en/function.curl-setopt.php
You'll want to turn off including the headers like this:
curl_setopt($ch, CURLOPT_HEADER, false);
Upvotes: 1