XML输出未显示在浏览器中

时间:2018-07-05 21:22:56

标签: php simplexml

我正在使用“ MYJADU” API来获取XML数据,然后解析该数据以进行显示,但是由于某种原因,该数据未在浏览器中显示。我不确定我缺少什么。下面是我到目前为止的代码。谢谢。

    <?p

    $path = 'http://{domain}/api/documents/all.xml?api_key={api_key}';

     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL,$path);
     curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 9.0; 
     Windows NT 6.1; Trident/5.0)');
     curl_setopt($ch, CURLOPT_USERAGENT, 'Jadu');
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

      $response = curl_exec($ch);
      curl_close($ch);

     $xml = new SimpleXMLElement($response); 
     foreach ($xml->document as $document) { 
     $documentTitle = (string) $document->title;
     echo htmlentities($documentTitle, ENT_QUOTES, 'UTF-8') . ‘<br>'
      }

     ?>

0 个答案:

没有答案