4

I am using the Zend Framework and using Zend_Http_Client to make a POST request to a third party API.

$client = new Zend_Http_Client('http://api.com');
$client->setParameterPost(array(
    'param1' => 'value'
));
$response = $client->request('POST');
echo $response->getBody();

This API returns an XML document as its response.

<?xml version="1.0" ?>
<registration>
    <id>12345</id>
</registration>

How can I turn the response into something I can work with?

1

3 Answers 3

13

I find the easiest way is to use SimpleXml

$data = simplexml_load_string($response->getBody());

Then, to get the ID, you can use

$id = (string) $data->registration->id;

Sign up to request clarification or add additional context in comments.

1 Comment

simplexml_load_string often segfaults as of this time. It seems unreliable.
2

for xml file from url, you can use below code.

$xml = simplexml_load_file('any url here');

echo $xml->id;

Comments

1

Is it XMLRPC? Look into Zend_XmlRpc. Otherwise: see Pekka's link in the comment on the Question, or use Zend_Config_Xml (not really what its intended for, though)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.