我有多个XML_PAYLOAD
要发布(每个while循环都有不同的xml帖子)。当我运行循环时,它只会POST
第一个$i
循环的数据。如何将每个POST
循环的$i
新数据转换为<{1}}?
$i = 0;
while ($i < $num) {
...data
define("XML_PAYLOAD", "<?xml stuff and tags?>");
define("XML_POST_URL", "http://theurl");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, XML_POST_URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POSTFIELDS, XML_PAYLOAD);
$result = curl_exec($ch);
curl_close($ch);
$i++;
}
答案 0 :(得分:1)
define定义了一个常量。这意味着它一旦设置就无法改变。你应该使用这样的变量:
define("XML_POST_URL", "http://theurl");
$i = 0;
while ($i < $num) {
...data
$xml_payload = "<?xml stuff and tags?>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, XML_POST_URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POSTFIELDS, XML_PAYLOAD);
$result = curl_exec($ch);
curl_close($ch);
$i++;
}