1

我将 Mink 与 Goutte webdriver 一起使用,试图用 XML 提要替换网站中表单的内容。

我编写了以下方法:

public function replaceField($field)
    {
        $baseText = '<?xml version="1.0" encoding="UTF-8"?>
<RiskAssessmentReply xmlns="http://test.com" >
    <!-- ExternalId of the Order --> 
    <OrderId>TO_REPLACE</OrderId>
    <RiskInfo>
        <Actions>
            <SystemAction>SystemAction</SystemAction>
            <FinalAction>FinalAction</FinalAction>
        </Actions>
        <Score SystemScore="0"/>
    </RiskInfo>
    <!-- One of Accept, Manual_Accept, Reject, Cancel, or Ignore --> 
    <ResponseCode>Accept</ResponseCode>
    <StoreId>TESTSTORE</StoreId>
</RiskAssessmentReply>';

        $textWithOrderId = preg_replace('/TO_REPLACE/', $GLOBALS['ORDER_ID'], $baseText);
        $this->getSession()->getPage()->fillField($field, $textWithOrderId);
    }

其中基本上包含 XML 提要,然后我将其中的一部分替换为我事先拥有的订单 ID 并调用该函数fillField与 Mink 捆绑在一起的函数。

问题是它不只是粘贴我提供的文本,而是通过在 " 符号之前设置反斜杠以一种奇怪的方式对其进行格式化,如下所示:

<?xml version=\"1.0\" encoding=\"UTF-8\"?>

因此,当我尝试提交 XML 提要时,网站显示以下错误:

|  Fatal error: Uncaught exception 'ErrorException' with message 'SimpleXMLElement::__construct(): Entity: line 1: parser error : String not started expecting ' or "'

我尝试使用stripslashesPHP 中的方法,但它不起作用,就好像我在添加订单 ID 后尝试回显它显示原始 XML 没有斜杠,所以我猜有调用其他一些函数使用fillField它时确实会在我的文本中添加反斜杠,但我无法找到它的来源。

有谁知道这种从"到的转换\"是在哪里进行的以避免它?

谢谢

4

2 回答 2

2

确保在 PHP 中关闭 Magic Quotes 设置,尤其是在您提交到的服务器上。自 PHP 5.4.0 起,它们已被删除。

魔术行情

于 2014-04-28T10:25:06.403 回答
1

确保在接收表单的页面中使用的是 stripcslashes 而不是 stripslashes。

于 2014-04-28T10:48:43.693 回答