Jump to content

Problem.. Different between file and string.


haku87

Recommended Posts

;)

I use this function call ProcessQns to get my data out.

<code>

<?php

function ProcessQns($data){

// Break the string into question groups.

$questions = preg_split('/\s+(?=\d+\.)/', $data, -1, PREG_SPLIT_NO_EMPTY);

// Loop...

$i = 0;

foreach ($questions as $question_group) {

// Get question.

preg_match('/^\d+\.\s+([^\r\n]+)/', $question_group, $matches);

$question = $matches[1];

// Get answers.

preg_match_all('/^\s+\*?[a-z]\.\s+([^\r\n]+)/sm', $question_group, $answers);

array_shift($answers);

preg_match_all('/^\s+\*?\*[a-z]\.\s+([^\r\n]+)/sm', $question_group, $answers2);

array_shift($answers2);

// Build result.

$result[$i]['question'] = $question;

$result[$i]['options'] = $answers[0];

$result[$i]['answers'] = $answers2[0];

++$i;

}

return $result;

}

?>

</code>

 

When I use $data = <<<DATA

1. The Pool Manager in Blackboard is

a. A high-schooler on their summer vacation

b. Paul Newman hustling Tom Cruise

*c. A mechanism for creating quizzes in Blackboard

 

2. PHP is

*a. A language

b. A fruit

c. A car

 

3. Regular Expressions are

a. A body language

*b. Awesome

c. Mathematical units

DATA;

 

It is working. However,  when I put this inside a text file and read from there using

$File = "./../quizbank/".$info['quizname'].".txt";

$Handle = fopen($File, 'r');

$content = fread($Handle, filesize($File));

fclose($Handle);

The function is not able to work.

What is the difference? 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.