0

次のテキストファイルがあります。

$string = 
'1 The most important feature of spiral model is: requirement analysis. risk    management. quality management. configuration management 2 The worst type of coupling is: Data coupling. control coupling. stamp coupling. content coupling 3 One of the fault base testing techniques is: unit testing. beta testing. Stress testing. mutation testing 4 A fault simulation testing technique is: Mutation testing. Stress testing. Black box testing. White box testing 5 RS is also known as: specification of White box testing. Stress testing. Integrated testing. Black box testing 6 what is you name: Collins. Achieng. Ogwethi. Kamanda';

次のコードは、複数の質問を選択するためのプルダウン メニューを備えたフォーム形式のテキスト ファイルと出力を読み取ります。このように進めようとしているのですが、

<html>
<head>
<title>read</title>
</head>
<body>
    <b><u> QUESTIONS AND ANSWERS QUIZ</u></b> <br /><br />
<?php
$openFile = fopen("questionandanswers.txt", "r") or exit ("unable to open the text       file");
$string = fread($openFile, filesize("questionandanswers.txt"));

//Regex to get from the first number to the string's end, so we ignore the Number     Question... bit;
preg_match('/\d.*/', $string, $match);

//We get all the strings starting with a number until it finds another number (which will be the beginning of another question;
preg_match_all('/\d\D*/', $match[0], $results);

$qas = array(); // We prepare an array with all the questions/answers
foreach($results[0] as $result){
//Separating the answer from the string with all the answers.
list($question, $all_answers) = explode(':', $result);

//Separating the different answers
$answers_array = explode('.', $all_answers);

//Stuffing the question and the array with all the answers into the previously prepared   array;
$qas[] = array('question' => $question, 'answers' => $answers_array);
}
?>
<form name="processor" action="processor.php" method="post">
<?php
//Looping through the array and outputting all the info into a form;
foreach($qas as $k => $v)?>
echo "<label>{$v['question']}</label><br/>";
echo "<select name='answers[]'>";

//we loop through $v['answers'] because its an array within the array with all the    answers.
foreach($v['answers'] as $answer)
{
    echo "<option>$answer</option>";//the output
}
echo "</select>";
echo "<br/><br/>";
?>
<input type="submit" value="Submit">
</form>
</body>
</html>

出力を $_POST として処理する別の php ファイルに出力を送信できるようにしたいと考えています。これで私を助けてくれる人はいますか?

4

1 に答える 1

0

この行を修正するだけでよいと思います:

echo "<select>";

に:

echo "<select name='answers[]'>";

processor.php ファイルでは、すべての回答を配列として選択できます。

var_dump($_POST['answers'])

しかし、文書モデルを壊しているように見えるので、この行を再考する必要があります:

<input type="text" name="question" value="<?
于 2013-04-20T15:55:37.957 に答える