function hotpot_utf8_to_html_entity in Quiz 6.6
Same name and namespace in other branches
- 6.5 includes/moodle/question/format/hotpot/format.php \hotpot_utf8_to_html_entity()
File
- includes/
moodle/ question/ format/ hotpot/ format.php, line 648
Code
function hotpot_utf8_to_html_entity($char) {
// http://www.zend.com/codex.php?id=835&single=1
// array used to figure what number to decrement from character order value
// according to number of characters used to map unicode to ascii by utf-8
static $HOTPOT_UTF8_DECREMENT = array(
1 => 0,
2 => 192,
3 => 224,
4 => 240,
);
// the number of bits to shift each character by
static $HOTPOT_UTF8_SHIFT = array(
1 => array(
0 => 0,
),
2 => array(
0 => 6,
1 => 0,
),
3 => array(
0 => 12,
1 => 6,
2 => 0,
),
4 => array(
0 => 18,
1 => 12,
2 => 6,
3 => 0,
),
);
$dec = 0;
$len = strlen($char);
for ($pos = 0; $pos < $len; $pos++) {
$ord = ord($char[$pos]);
$ord -= $pos ? 128 : $HOTPOT_UTF8_DECREMENT[$len];
$dec += $ord << $HOTPOT_UTF8_SHIFT[$len][$pos];
}
return '&#x' . sprintf('%04X', $dec) . ';';
}