PHP 数组元素未放入字符串中(错误)



以下代码无法按预期工作...

curl_setopt($ch, CURLOPT_POSTFIELDS, "password="+$alphas[$x]+"&submit=yes");

$alphas[$x] 部分似乎通过将字母放入字符串中不起作用。下面几行我呼应$alphas[$x],效果很好。

例如,如果我将第一行代码更改为...

curl_setopt($ch, CURLOPT_POSTFIELDS, "password=j&submit=yes");

它按预期完美运行,因此我认为$alpahs[$x] 没有像它应该的那样将字母放入字符串中。

$content = "7";
$x = 0;
$alphas = array_merge(range("A", "Z"), range("a", "z"));
while($x < 52) {
print_r($alphas[$x]);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_URL, "/Demo/form.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "password="+$alphas[$x]+"&submit=yes");
$content=curl_exec($ch);
echo $content;
echo "Pass: ";
echo $alphas[$x];
echo "<br>";
$x++;
}

点是字符串连接运算符,而不是加号:

curl_setopt($ch, CURLOPT_POSTFIELDS, "password=".$alphas[$x]."&submit=yes");

还可以使用以下语法将变量插入到双引号字符串中:

curl_setopt($ch, CURLOPT_POSTFIELDS, "password={$alphas[$x]}&submit=yes");

相关内容

最新更新