0

I'm pretty new to using Laravel (5.1)/PHP and especially doing anything with the Guzzle HTTP package. I have an api I'm trying to return a response from. I'm successfully getting the response, but I need to save pieces of it to variables to use later in my applicaiton

How do I parse through the response to get the pieces of xml that I need, say anything within <status>Passing</status>?

The following retrieves the entire xml response.

use GuzzleHttp\Client;

$client = new Client();
$res = $client->request('GET', 'https://api.com?parameter=value');
$body = $res->getBody();
echo $body;

Thanks for your help!

Moose
  • 1,231
  • 4
  • 14
  • 22

1 Answers1

0

I'm not super familiar with Guzzle but try this.

$xml = $response->xml();
$status = $xml->status;

Here's the documentation from which I based this off of:

http://guzzle3.readthedocs.org/http-client/response.html#xml-responses

pajamas
  • 110
  • 6
  • 2
    I should have added I'm using the latest version of Guzzle (6) and the xml method you specified is not included. :-( – Moose Dec 22 '15 at 21:26
  • $client = new \GuzzleHttp\Client(); $response = $client->request('GET', 'yourURL'); $response = $response->getBody()->getContents(); return $response; – Rashi Goyal Sep 26 '17 at 08:50