title: Send Request to a Web Service with PHP and cURL
body: <p>I'm learning how to send a request to a web service using PHP and cURL. I found this link and was able to get the 'zip code' example to work.</p>
  
  <p><a href="https://stackoverflow.com/questions/1379339/consume-webservice-with-php">Consume WebService with php</a></p>
  
  <p>WebserviceX.NET also has 'stock quote' web service.</p>
  
  <p><a href="http://www.webservicex.net/ws/WSDetails.aspx?CATID=2&amp;WSID=9" rel="nofollow noreferrer">http://www.webservicex.net/ws/WSDetails.aspx?CATID=2&amp;WSID=9</a></p>
  
  <p>I'm using the same method used for the 'zip code' example but I can't get this one to work. Here is the code.</p>
  
  <pre><code>$url = "http://www.webservicex.net/stockquote.asmx/GetQuote?symbol=AAPL";
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $result = curl_exec($ch);
  curl_close($ch);
  $xmlobj = simplexml_load_string($result);
  </code></pre>
  
  <p>The code runs successfully but I can't access the XML object. I thought this would work.</p>
  
  <pre><code>echo $xmlobj-&gt;StockQuotes-&gt;Stock-&gt;Symbol;
  </code></pre>
  
  <p>The issue seems to be that $result is not in the right format or it's not loading into the XML object correctly. I have tried many approaches using DOMDocument and SimpleXMLElement but I can't figure it out.</p>