文字列にファイルの内容を読む、その後
$pages = explode('break_page;', $contents);
// => [
// """
// Question asks why what happens?; 1)Atlantic; 2)Pacific; 3)Mediteran;\n
// This is another question again?; 1)A; 2)B; 3)C;\n
// """,
// """
// \n
// Some other question?; 1)X; 2)Y; 3)Z; 4)fUcK;\n
// """,
// """
// \n
// 3rd page question?; 1)Use; 2)A; 3)Database; 4)Instead; 5)Of; 6)This;\n
// \n
// """,
// ]
質問を表現するために、各ページの各ラインを破って:
$contents = file_get_contents('quest.txt');
// => """
// Question asks why what happens?; 1)Atlantic; 2)Pacific; 3)Mediteran;\n
// This is another question again?; 1)A; 2)B; 3)C;\n
// break_page;\n
// Some other question?; 1)X; 2)Y; 3)Z; 4)fUcK;\n
// break_page;\n
// 3rd page question?; 1)Use; 2)A; 3)Database; 4)Instead; 5)Of; 6)This;\n
// \n
// """
その後のページでそれを破りますその可能な回答:
foreach ($pages as $page) {
$lines = array_filter(explode(PHP_EOL, $page));
// => [
// "Question asks why what happens?; 1)Atlantic; 2)Pacific; 3)Mediteran;",
// "This is another question again?; 1)A; 2)B; 3)C;",
// ]
foreach ($lines as $line) {
$segments = array_filter(array_map('trim', explode(';', $line)))
// => [
// "Question asks why what happens?",
// "1)Atlantic",
// "2)Pacific",
// "3)Mediteran",
// ]
// Do whatever you want with them...
}
}
そして、真剣に、データベースを使用してください。
テキストファイルを使用しないでください。データベースを使用してください –