$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 Feed。但是使用这个开头<<<TEXT
会弄乱它下面的所有代码。我没有得到任何错误,代码工作,但我下面的所有PHP代码是黑色的,老实说,只是不容易管理。如果我把它取出,xml feed无法正常运行。有人能告诉我为什么这有效,有什么更好的方法来实现这一目标?我到处搜索,没有找到关于这个主题的内容。请帮忙!
感谢任何人提前花时间回答!
答案 0 :(得分:2)
这是字符串的 Heredoc 语法。
将Heredoc用于字符串有利于多行字符串,并且可以避免引用问题。
答案 1 :(得分:0)
这是一个HEREDOC字符串,如果你遇到问题,可能是由于关闭序列的缩进:
TEXT; //&lt; - 必须位于文本文件的第0列。
http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc