-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

引用符が混同されているようです-\'の部分は必要ありません:

$_POST["variable_" . $index]

于 2012-12-31T07:07:34.673 に答える
0

間違いがsingleあり、double引用

fwrite($outfile, $_POST["'variable_" . $index."'"]);
于 2012-12-31T07:07:40.053 に答える
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
fwrite($outfile, implode("\r", array_values($_POST)));
于 2012-12-31T07:10:53.893 に答える