With the following text file

$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)   Which of these terms is a level name in the Capability Maturity Model?: Ad hoc. Repeatable. Reusable. Organized 7)  FP-based estimation techniques require problem decomposition based on?: Information domain values. project schedule. software functions. process activities 8)  What types of models are created during software requirements analysis?: Functional and behavioral. Algorithmic and data structure. Architectural and structural. Usability and reliability 9)  Which of the following is not an attribute of software engineering: Efficiency. Scalability. Dependability. Usability

I want to be able to loop through the regex such that I diaply one question at a time, such that after submitting one it proceeds to the next one. These are the codes that I have that reads teh above text file.Thank you.

such that after submitting one it proceeds to the next one

You will have to keep track of the last index used, whichever method you use. What's the reason for using a string like that?

Thank you for the insights, Actually have no idea have how to go about that...

Let me look at substr and strpos and see how to implement them thank you.

This was what guided my text file:

The questions will be finished with a colon(:).
The answers will be finished with a dot(.), all of them but the last one, as we will use the number of the question as separator.
The questions or answers won't contain any numbers [0-9] or it will confuse the regex.

How will I be able to implement the substr() and strpos(() based on my research for the last 2 hours they deal with characters only.

How will I implement the above mention function in the following and do away with the

fread ()

fucntion and introduce

fget ()

That reads line by line.
Actually hre is my regex code:

$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 that will store the questions/answers
foreach($results[0] as $result)
{
    //Separating the question from the string with all the answers.
    list($question, $all_answers) = explode(':', $result);

    //Separating the different answers

    $answers_array = explode('.', $all_answers);

    //removes unnecesary spaces in the questions

    $answers_array_trimmed = array_map('trim', $answers_array);

    //Storing the question and the array with all the answers into the previously prepared array;

    $qas[] = array('question' => $question, 'answers' => $answers_array);
}
//Looping through the array and outputting all the info into a form;

$questionNr = 0;    
foreach($qas as $k=>$v)
    {
    echo "<input id='question{$questionNr}' style='width:40%' type='text' value='".$v['question']."' name='questions[]' >";
    echo '<br /><br />';
//Puts the answers of each question unique and in the form of radios
    foreach($v['answers'] as $answer)
        {
        echo "<input type=\"radio\" name=\"selected_answers[$questionNr]\" value=\"$answer\" />";
        echo "$answer";
        echo '<br/><br />';
        }
    $questionNr++;
    }
?>
<input name= "submit" type="submit" value="Submit Answers">&nbsp <input type="reset" value ="Clear Answers">
</form>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.