Skip to content

Instantly share code, notes, and snippets.

@liuxd
Created June 15, 2022 21:59
Show Gist options
  • Save liuxd/327523e8d9a0d4c6da09a27f2e86e42b to your computer and use it in GitHub Desktop.
Save liuxd/327523e8d9a0d4c6da09a27f2e86e42b to your computer and use it in GitHub Desktop.
[Parsing SOAP xml in PHP]
<?php
function parseSOAP(string $response): array
{
$content = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $response);
$xml = new SimpleXMLElement($content);
$body = $xml->xpath('//sBody')[0]; // 'sBody' is from '<s:Body>', the body tag in your xml file.
$json = json_encode((array)$body, JSON_THROW_ON_ERROR);
$data = json_decode($json, true, 512, JSON_THROW_ON_ERROR);
return $data
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment