1
PHPのテキストドキュメントから質問を読んで、array()
でソートしたいと思っています。プレーンテキストファイルからの質問を読む
結果の配列は次のようになります。
print_r($questionnaire);
array(
'question 1' => array('yes','no'),
'question 2' => array('yes','no'),
'question 3' => array('yes','no'),
...etc
)
マイテキストドキュメントがある:私はこれをしようとしています
question 1?
yes
no
question 2?
yes
no
question 3?
yes
no
:
出力を生成するために$txt_doc = $_FILES['txt_doc']['tmp_name'];
$questions_and_answers = array();
$handle = fopen($txt_doc, 'r') or die($txt_doc . ' : CAnt read file');
$i = 0;
while (! feof($handle))
{
$line = trim(fgets($handle));
if(strstr($line, '?'))//its a question
{
$questions_and_answers[$i] = $line;$i++;
}
if(!strstr($line, '?'))
{
$questions_and_answers[$i][] = $line;
}
}
これを実行するとどうなりますか?あなたが期待していることをしていない場合は、代わりに何をしているのか説明できますか? –