【问题标题】:<<<TEXT is being using in php variable to output xml? [duplicate]<<<TEXT 在 php 变量中用于输出 xml? [复制]
【发布时间】:2012-09-27 01:39:47
【问题描述】:
$xmlSend = <<<TEXT
                    <?xml version="1.0" encoding="UTF-8"?>
                        <VMCAMEXM>
                            <business>
                                <id_company>{$idCompany}</id_company>
                                <id_branch>{$idBranch}</id_branch>
                                <country>{$Country}</country>
                                <user>{$User}</user>
                                <pwd>{$pwd}</pwd>
                            </business>
                            <transacction>
                                <merchant>{$Merchant}</merchant>
                                <reference>50000</reference>
                                <tp_operation>13</tp_operation>
                                <creditcard>
                                    <crypto>{$Crypto}</crypto>
                                    <type>V/MC</type>
                                    <name>{$name}</name>
                                    <number>{$number}</number>
                                    <expmonth>{$expmonth}</expmonth>
                                    <expyear>{$expyear}</expyear>
                                    <cvv-csc>{$cvv}</cvv-csc>
                                </creditcard>
                                <amount>{$cantidad}</amount>
                                <currency>{$Currency}</currency>
                                <usrtransacction>1</usrtransacction>
                            </transacction>
                        </VMCAMEXM>
TEXT;

echo "<pre>";
print_r(htmlspecialchars($xmlSend));
echo "</pre>";

            //$url = $tUrl;         
            $vars = "&xml=" . $rc4->limpiaVariable(urlencode($xmlSend)); 
            $header[] = "Content-type: application/x-www-form-urlencoded";
            $ch = curl_init();
            $postfields = "info_asj3=1".$vars;

             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
             curl_setopt($ch, CURLOPT_URL,$Url);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($ch, CURLOPT_TIMEOUT, 250);
             curl_setopt($ch, CURLOPT_POST, true);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
             curl_setopt($ch, CURLOPT_HTTPHEADER, $header);          

             $data = curl_exec($ch);
                if (curl_errno($ch)) {
                   $data = curl_error($ch);          
                } else {
                   curl_close($ch);
                }

我正在与一家新公司合作,该公司正在使用它连接到 xml 提要。但是使用这个开头&lt;&lt;&lt;TEXT 会弄乱它下面的所有代码。我没有收到任何错误,代码可以工作,但是我下面的所有 php 代码都是黑色的,老实说不容易管理。如果我把它拿出来,xml 提要就不能正常工作。有人可以告诉我为什么这是有效的,什么是更好的方法来实现这一点?我到处搜索,找不到关于该主题的任何内容。请帮忙!

提前感谢任何人抽出时间回答!

【问题讨论】:

标签: php xml curl


【解决方案1】:

这是字符串的Heredoc语法。

对字符串使用 Heredoc 对多行字符串有好处,可以避免引用问题。

【讨论】:

    【解决方案2】:

    这是一个HEREDOC字符串,如果遇到问题,可能是由于结束序列的缩进:

    文本; //

    http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

    【讨论】:

      猜你喜欢
      • 2014-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-06
      • 2019-04-21
      • 2017-01-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多