繁体   English   中英

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

[英]PHP Array Element Not Getting Put In String (Error)

以下代码无法正常运行...

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");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM