Hi,
First of all before you read a text file (survey.txt), you need to define a particular way your file has the contents.
For eg: if you have your survey questions and options, then your file may have a format as given below:
What is an average age?
1. 17-20
2. 21-23
3. 24-27
What is the average height?
1. 5.4-5.6 Ft
2. 5.7-5.10 Ft
3. 5.10-6.0 Ft
I hope you get this. It has question in first line, 1st option/value in 2nd line, 2nd option/value in 3rd line, 3rd option/value in 4th line, and this is a repetitive process... That means you have 4xn lines (where n = no. of questions)
So this way you decide your format of the file and now read from it.
$fh = fopen ("survey.txt",r);
$cnt = 1;
while($data = fgets($fh))
{
switch($cnt)
{
case 1: //This gets the question
break;
case 2: //This gets the first option/value from file
break;
case 3: //This gets the second option\value from file
break;
case 4: //This gets the second option\value from file
break;
}
$cnt++;
// Read till 4 lines - After 4 lines a question is read. Restart the counter once a question is read.
if($cnt>4)
$cnt=1;
}
fclose($fh);
So now its up to you to design your survey.txt file and then proceed with a code (custom code) to read the contents the way you stored.
All the best. Write in more if you still confused. Or you can share your code if you stuck somewhere.