Jump to content

Recommended Posts

I do see what you meen, but i don't get the result i whant from that.

But i may have missed completly on the bitt of code.....

Here is what i want to happen:

 

I as making a smal quiz.

the question file looks like this: (submitted by users)

<q> What is your name?

<a1> Thomas

<a2> Roger

<a3> John

--end of file--

 

I want to make a script that identify each line ass a question(q) or an alternative(a1,a2,a3......) and buts the line into a string

so i can print it on the page in the right order.

 

can anyone help me out here?

Link to comment
https://forums.phpfreaks.com/topic/55830-hmm/
Share on other sites

 

Hello,

 

 

I do not get a clear idea about your requirement. What I understood is :

 

Read the line of strings and identify it as a question or an answer and print it?

 

Could you please post the strings u need to be processed ?

 

Regards

Aniesh Joseph

anieshjoseph@gmail.com

Link to comment
https://forums.phpfreaks.com/topic/55830-hmm/#findComment-275795
Share on other sites

Hello,

 

Make two tables named tableQuestions & tablesAnswers with the following field.

 

tableQuestions

--------------

 

id Question

1 What is your name?

2 Your favourite place?

 

tablesAnswers

-------------

 

id questionID answers

1 1 Thomas

2 1 Roger

3 1 John

4 2 US

5 2 UK

6 2 India

 

 

I think u got the right way to start.

 

Regards

Aniesh Joseph

anieshjoseph@gmail.com

Link to comment
https://forums.phpfreaks.com/topic/55830-hmm/#findComment-275802
Share on other sites

File to bee read:

<q> what is your name?

<a1> Thomas

<a2> Roger

<a3> John

 

 

 

Result i want:

                                  Question: What is your name?  ($question = What is your name?)

posible answers:

                                  Alternative 1: Thomas            ($a1 = Thomas)

                                  Alternative 2: Roger              ($a2 = Roger)

                                  Alternative 3: John                ($a3 = John)

 

Link to comment
https://forums.phpfreaks.com/topic/55830-hmm/#findComment-275803
Share on other sites

nah he said he doesn't want to use a database.

----------------------------

 

Question: What is your name?  ($question = What is your name?)

 

What the answer is.

$answer1 = "John";

($answer1 = $a3)

 

                                  Alternative 1: Thomas            ($a1 = Thomas)

                                  Alternative 2: Roger              ($a2 = Roger)

                                  Alternative 3: John                ($a3 = John)

 

if($answer1 = $a3) {

echo("Correct, the answer was $answer1.");

}

else {

echo("Wrong, the answer was not $answer1.");

}

 

 

Something along those lines. and of course you will have the form coding and what not to work with it.

 

Regards ACE

Link to comment
https://forums.phpfreaks.com/topic/55830-hmm/#findComment-275806
Share on other sites

hello,

 

Please copy the following lines of code. This reads a file named "data.txt" with the content

 

/*  File Name :: data.txt  */

 

<q> what is your name?

<a1> Thomas

<a2> Roger

<a3> John

 

/*  File Name :: show.php  */

<?

error_reporting(E_ERROR ^ E_WARNING);

$handle = @fopen("data.txt", "r");

if ($handle)

{

    while(!feof($handle))

{

      $buffer = fgets($handle, 4096);

$pattern = '/<a(.*)>(.*)/';

$no_of_matches = preg_match($pattern,$buffer,$matches);

if($no_of_matches)

{

$answer = $matches[2];

$key = $a.$matches[1];

$array[$key] = $answer;

}

 

$qPattern = '/<q>(.*)/';

$noMatches = preg_match($qPattern,$buffer,$qMatches);

if($noMatches > 0)

{

$question = $qMatches[1];

}

 

    }

 

    fclose($handle);

 

echo "<br> Questions is: ".$question;

 

foreach($array as $key => $val)

{

echo "<br> Answer $key: $val";

 

}

 

}

 

?>

 

 

I code it very fastly so if u find any bugs, pls reply

 

Regards

Aniesh Joseph

anieshjoseph@gmail.com

Link to comment
https://forums.phpfreaks.com/topic/55830-hmm/#findComment-275820
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.