-1

我在 while 循环中收到以下错误:

解析错误:语法错误,意外的 T_ENCAPSED_AND_WHITESPACE,期待 T_STRING

$index=1;
while ($index <= 100):

fwrite($outfile, $_POST[\'"variable_" . $index\']);
fwrite($outfile, "\r");


$index = $index + 1;
endwhile;
fclose($outfile);
?>

包含 variable_1、variable_2、variable_3 而不会出现语法错误的正确方法是什么?

谢谢。

4

4 回答 4

0
fwrite($outfile, implode("\r", array_values($_POST)));
于 2012-12-31T07:10:53.893 回答
0
$x = "variable_$index";
fwrite($outfile, $_POST[$x]);

我也会考虑在这里使用 for 循环。

// Assuming you open $outfile somewhere prior to this
for ( $i = 1; $i <= 100; $i++ ) {
    $x = "variable_$i";
    fwrite($outfile, $_POST[$x]);
    fwrite($outfile, "\r");
} 
fclose($outfile);
于 2012-12-31T07:06:32.520 回答
0

看起来您的引号混淆了 - 您不需要 \' 部分:

$_POST["variable_" . $index]

于 2012-12-31T07:07:34.673 回答
0

有错误singledouble引号

fwrite($outfile, $_POST["'variable_" . $index."'"]);
于 2012-12-31T07:07:40.053 回答