XML响应回应屏幕而不是返回变量

时间:2014-03-08 03:02:34

标签: php xml

我有一些PHP代码,包括一个XML生成和发送类,允许我的业务合作伙伴向我发送信息。除了回应之外,它的工作就像一场梦。它不断将XML响应打印到屏幕上。

他们的PHP页面(我可以控制),生成并发送(通过CURL POST)XML到我的站点的接收PHP页面,该页面处理数据(正确)并回显XML成功/错误响应。即使我尝试在类变量中捕获响应或者只是将其从PHP页面返回到变量中,它仍然在页面上显示XML响应并且不起作用,它只需要以编程方式处理。 / p>

业务合作伙伴的PHP:

$hbn = new hbnXML;
$hbn->UpdateType = "Update";
$hbn->Populate($hbnData);

//echo "creating base<br>";
$hbn->createXMLBase();
//echo "createing XML<br>";
$hbn->createXML();
//echo "sending XML<br>";
$result = $hbn->sendXML();
// i want to process $result here
//echo "RESULT: $result<br>";

相关课程fxn:

   function sendXML(){
        $url = "http://mywebsite.com/receiveXML";
    //setting the curl parameters.
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    // Following line is compulsary to add as it is:
    curl_setopt($ch, CURLOPT_POSTFIELDS,
                "xmlRequest=" . html_entity_decode($this->xml, ENT_COMPAT, 'UTF-8'));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
    curl_setopt($ch, CURLOPT_TIMEOUT, 120);
    $result = curl_exec($ch);
            if (!$result) {
                echo "<p>cURL error number: " .curl_errno($ch) . " on URL: " . $url ."</p>" . "<p>cURL error: " . curl_error($ch) . "</p>";
            }
            if($result && $result != "Success"){
               print $result;
            }
    curl_close($ch);
    return $result;

}

receiveXML.php:打印XML响应的行

if($update_id){
   header("Content-type: text/xml; charset=utf-8");
   echo genXMLResponse("Success",null);
}

1 个答案:

答案 0 :(得分:0)

这似乎是对print陈述的简单监督。 curl_exec()事务将XML字符串返回到$response,如果$response != "Success"则打印该字符串。如果它确实包含XML,$response可能永远不会== "Success",因此始终会打印出来。

$result = curl_exec($ch);
// You already handled errors here, $result contains XML.
if (!$result) {
   echo "<p>cURL error number: " .curl_errno($ch) . " on URL: " . $url ."</p>" . "<p>cURL error: " . curl_error($ch) . "</p>";
}

// Remove this block..
// if($result && $result != "Success"){
//   print $result;
// }