I tried to run the code below, i get an error message that
However if i take my input from a local text file e.g.The following tags were not closed: questions. Error processing resource
$fp = fopen('questiontext.txt', 'r'); instead of
$mytext = $HTTP_POST_VARS["mytext"];
$fp = $mytext;
the script works OK.
Can anyone spot what i am doing wrong.
Any suggestions will be appreciated.
Code: Select all
credit: volka (sept03)
<?php
header('Content-Type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
echo "<questions>\n";
//patterns to describe delimiters
$patternQuestion = '!^\d+їa-z]+\.\s+(.+)!';
$patternChoice = '!^її:alpha:]]+\.\s+(.+)!';
$bInItem = false; // the only element not to be handled in one line
$mytext = $HTTP_POST_VARSї"mytext"];
$fp = $mytext;
while(!feof($fp))
{
$row = trim(fgets($fp, 2048));
if (strlen($row) > 0)
{
//search for a match to expression given in questionPattern
if (preg_match($patternQuestion, $row, $matches))
{
if ($bInItem)
echo "</item>\n";
else
$bInItem = true;
echo "<item>\n <question>$matchesї1]</question>\n";
}
else if(preg_match($patternChoice, $row, $matches))
echo " <choice>$matchesї1]</choice>\n";
else
echo '# ', $row, "#\n";
}
}
if ($bInItem)
echo '</item>';
echo '</questions>';
?>