title: PHP - SOAP response to JSON
body: <p>I am trying to parse SOAP response to JSON. So far I have this code:</p>
  
  <pre><code>$data = '&lt;?xml version="1.0" encoding="utf-8"?&gt;';
      $data .= '&lt;soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"&gt;';
      $data .= '&lt;soap12:Body&gt;';
      $data .= '&lt;GetCommunities xmlns="url"&gt;';
      $data .= '&lt;APIUsername&gt;string&lt;/APIUsername&gt;';
      $data .= '&lt;APIPassword&gt;string&lt;/APIPassword&gt;';
      $data .= '&lt;/GetCommunities&gt;';
      $data .= '&lt;/soap12:Body&gt;';
      $data .= '&lt;/soap12:Envelope&gt;';
  
      $soap_do = curl_init();
      curl_setopt($soap_do, CURLOPT_URL,            "url" );
      curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
      curl_setopt($soap_do, CURLOPT_TIMEOUT,        10);
      curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
      curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
      curl_setopt($soap_do, CURLOPT_POST,           true );
      curl_setopt($soap_do, CURLOPT_POSTFIELDS,     $data);
      curl_setopt($soap_do, CURLOPT_HTTPHEADER,     array('Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen($data) ));
  
      $result = curl_exec($soap_do);
  echo $result;
  </code></pre>
  
  <p>This code is working and I am getting following result:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
      &lt;soap:Body&gt;
          &lt;GetCommunitiesResponse xmlns="url"&gt;
              &lt;GetCommunitiesResult&gt;
                  &lt;Communities&gt;
                      &lt;CommunityID&gt;1&lt;/CommunityID&gt;
                      &lt;CommunityName&gt; Not Specified&lt;/CommunityName&gt;
                  &lt;/Communities&gt;
                  &lt;Communities&gt;
                      &lt;CommunityID&gt;276&lt;/CommunityID&gt;
                      &lt;CommunityName&gt;Bella Toscana&lt;/CommunityName&gt;
                  &lt;/Communities&gt;
                  &lt;Communities&gt;
                      &lt;CommunityID&gt;31&lt;/CommunityID&gt;
                      &lt;CommunityName&gt;Crescent Lakes&lt;/CommunityName&gt;
                  &lt;/Communities&gt;
                  &lt;Communities&gt;
                      &lt;CommunityID&gt;62&lt;/CommunityID&gt;
                      &lt;CommunityName&gt;Hillcrest Estate&lt;/CommunityName&gt;
                  &lt;/Communities&gt;
                  &lt;Communities&gt;
                      &lt;CommunityID&gt;750&lt;/CommunityID&gt;
                      &lt;CommunityName&gt;Sunny Beach&lt;/CommunityName&gt;
                  &lt;/Communities&gt;
                  &lt;Communities&gt;
                      &lt;CommunityID&gt;124&lt;/CommunityID&gt;
                      &lt;CommunityName&gt;Terra Verde Resort&lt;/CommunityName&gt;
                  &lt;/Communities&gt;
                  &lt;Communities&gt;
                      &lt;CommunityID&gt;744&lt;/CommunityID&gt;
                      &lt;CommunityName&gt;The Dales at West Haven&lt;/CommunityName&gt;
                  &lt;/Communities&gt;
                  &lt;Communities&gt;
                      &lt;CommunityID&gt;158&lt;/CommunityID&gt;
                      &lt;CommunityName&gt;Westridge&lt;/CommunityName&gt;
                  &lt;/Communities&gt;
              &lt;/GetCommunitiesResult&gt;
          &lt;/GetCommunitiesResponse&gt;
      &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>I need to create JSON response from the data which can be found between <strong>GetCommunitiesResult</strong> tags. How can I do this?</p>