Created
June 15, 2022 21:59
-
-
Save liuxd/327523e8d9a0d4c6da09a27f2e86e42b to your computer and use it in GitHub Desktop.
[Parsing SOAP xml in PHP]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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