douping7975 2011-09-28 23:28
浏览 31
已采纳

帮助PHP的XML响应

I am new to PHP, and I am using it to POST data from an iPhone. I have written a basic code to get data from the iPhone, post it to the php script on my server, and then using PHP, send that data to another webserver. However, the webserver is returning a response in XML, and since I am a newbie to PHP, I need help with it. My code to send data:

<?php
$ch = curl_init("http://api.online-convert.com/queue-insert");
$count = $_POST['count'];

$request["queue"] = file_get_contents($count);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$response = curl_exec($ch);
curl_close ($ch);
echo $response;
?>

I know I need to parse the XML response, but I have no idea how to do that. The XML response would be something like this:

    <?xml version="1.0" encoding="utf-8"?>
<queue-answer>
  <status>
    <code>0</code>
    <message>Successfully inserted job into queue.</message>
  </status>
  <params>
    <downloadUrl>http://www.online-convert.com/result/07d6c1491bb5929acd71c531122d2906</downloadUrl>
    <hash>07d6c1491bb5929acd71c531122d2906</hash>
  </params>
</queue-answer>
  • 写回答

3条回答 默认 最新

  • dsgdg46465 2011-09-28 23:30
    关注

    You're probably looking for SimpleXML or DOMDocument.

    SimpleXML

    To load data from a string into an object: simplexml_load_string().

    DOMDocument

    To create one from a string: DOMDocument->loadXML().

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题