解析来自 CURL 的 XML 响应 - 困惑
使用 CURL,我将 xml 文件发送到服务器,并从所述服务器接收 200 响应和相应的 XML 文件。
$response = curl_exec($session);
到目前为止,一切都很好。如果我执行print_r($response)
,我会发现我需要的网址确实在$response
内。
我的问题是如何解析它?我尝试了以下的变体,但似乎没有任何效果:
$xml = new SimpleXMLElement($response);
指向正确方向的指针会很棒。
谢谢!
Using CURL, I send an xml file to a server and receive a 200 response and reciprocal XML file from said server.
$response = curl_exec($session);
So far so good. If I do print_r($response)
I see that the url i need is indeed inside $response
.
The question i have is how do i parse it out? I try variations of the following but nothing seems to work:
$xml = new SimpleXMLElement($response);
Pointer in the right direction would be great.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要设置正确的卷曲选项。看起来标头信息包含在响应数据中,这当然会使响应无效 XML。您可以在此处查看curl选项:
http://www.php.net /manual/en/function.curl-setopt.php
您需要关闭包含这样的标题:
You need to set the right curl options. It looks like the header information is being included in the response data, which of course makes the response invalid XML. You can see the curl options here:
http://www.php.net/manual/en/function.curl-setopt.php
You'll want to turn off including the headers like this:
您需要使用以下结构:
You need use the following structure: