--- wct_qti_lib.php 2006-06-26 06:29:32.000000000 -0400 +++ wct_qti_lib.php 2008-04-04 16:31:12.000000000 -0400 @@ -56,19 +56,31 @@ // Load the file into memory $filedata = convertWctEquations(implode('', file($file))); - + + // Convert to UTF-8 + $encoding = extractQtiXmlEnconding($filedata); + $logpage .= "\n
Detected questionDB.xml encoding: $encoding
"; + $filedata = iconv($encoding,"UTF-8",$filedata); + // Split it into sections $sects = extractQtiSections($filedata); $numqsadded = 0; @@ -252,6 +268,17 @@ return $qz->instance; } +// Returns the encoding of the file as specified by the XML declaration +function extractQtiXmlEnconding($filedata){ + if (preg_match('/]*encoding=[\'"](.*?)[\'"][^>]*?>/m', $filedata, $encmatch)) { + return strtoupper($encmatch[1]); + } + else { + // Default to "usual" encoding + return "WINDOWS-1252"; + } +} + // Returns an array of objects, one per section, with their uninterpreted itemmy-content stored as ->CONTENT function extractQtiSections($filedata){ // Simply split by spotting