for ($i = 0; $i < $length; $i++) {
$size = mt_rand(20, 28);
$angle = mt_rand(-15, 15);
$x = ($width/$length) * $i + $textWidth;
$y = mt_rand($height/2, $height - $textHeight);
$rand_color = getRandColor($image); //随机颜色
$text = str_shuffle($string){0}; //打乱顺序并且取第一个
//生成验证码
imagettftext($image, $size, $angle, $x, $y, $rand_color, $fontFile, $text);
}这样子的话运行会提示有问题
Parse error: syntax error, unexpected '{' in D:\phpStudy\WWW\mooc_gd\2_4.php on line 42
如果改成[0]就可以运行了
那你这样做可以就行了。