haku87 Posted April 15, 2007 Share Posted April 15, 2007 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? Link to comment https://forums.phpfreaks.com/topic/47091-problem-different-between-file-and-string/ Share on other sites More sharing options...
Orio Posted April 15, 2007 Share Posted April 15, 2007 Use file_get_contents($filename) Orio. Link to comment https://forums.phpfreaks.com/topic/47091-problem-different-between-file-and-string/#findComment-229664 Share on other sites More sharing options...
haku87 Posted April 15, 2007 Author Share Posted April 15, 2007 I get the same problem as well. I try it before Link to comment https://forums.phpfreaks.com/topic/47091-problem-different-between-file-and-string/#findComment-229669 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.