From 4b46d4df9b2a30afec9fdb5d950474b081e944f8 Mon Sep 17 00:00:00 2001 From: bobopinna Date: Thu, 11 Aug 2005 06:44:45 +0000 Subject: [PATCH] Removed double char conversion and added PHPDoc comments --- mod/scorm/xml2array.class.php | 64 +++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/mod/scorm/xml2array.class.php b/mod/scorm/xml2array.class.php index 11b0549b7df..4b81f5f5dff 100644 --- a/mod/scorm/xml2array.class.php +++ b/mod/scorm/xml2array.class.php @@ -13,33 +13,45 @@ class xml2Array { var $resParser; var $strXmlData; + /** + * Convert a utf-8 string to html entities + * + * @param string $str The UTF-8 string + * @return string + */ function utf8_to_entities($str) { - $entities = ''; - $values = array(); - $lookingfor = 1; - - for ($i = 0; $i < strlen($str); $i++) { - $thisvalue = ord($str[$i]); - if ($thisvalue < 128) { - $entities .= chr($thisvalue); - } else { - if (count($values) == 0) { - $lookingfor = ($thisvalue < 224) ? 2 : 3; - } - $values[] = $thisvalue; - if (count($values) == $lookingfor) { - $number = ($lookingfor == 3) ? - (($values[0] % 16) * 4096) + (($values[1] % 64) * 64) + ($values[2] % 64): - (($values[0] % 32) * 64) + ($values[1] % 64); - $entities .= '&#' . $number . ';'; - $values = array(); - $lookingfor = 1; - } - } - } - return $entities; - } - + $entities = ''; + $values = array(); + $lookingfor = 1; + + for ($i = 0; $i < strlen($str); $i++) { + $thisvalue = ord($str[$i]); + if ($thisvalue < 128) { + $entities .= $str[$i]; // Leave ASCII chars unchanged + } else { + if (count($values) == 0) { + $lookingfor = ($thisvalue < 224) ? 2 : 3; + } + $values[] = $thisvalue; + if (count($values) == $lookingfor) { + $number = ($lookingfor == 3) ? + (($values[0] % 16) * 4096) + (($values[1] % 64) * 64) + ($values[2] % 64): + (($values[0] % 32) * 64) + ($values[1] % 64); + $entities .= '&#' . $number . ';'; + $values = array(); + $lookingfor = 1; + } + } + } + return $entities; + } + + /** + * Parse an XML text string and create an array tree that rapresent the XML structure + * + * @param string $strInputXML The XML string + * @return array + */ function parse($strInputXML) { $this->resParser = xml_parser_create ('UTF-8'); xml_set_object($this->resParser,$this);