You are here

function hotpot_charcode_to_utf8 in Quiz 6.6

Same name and namespace in other branches
  1. 6.5 includes/moodle/question/format/hotpot/format.php \hotpot_charcode_to_utf8()

File

includes/moodle/question/format/hotpot/format.php, line 627

Code

function hotpot_charcode_to_utf8($charcode) {
  if ($charcode <= 0x7f) {

    // ascii char (roman alphabet + punctuation)
    return chr($charcode);
  }
  if ($charcode <= 0x7ff) {

    // 2-byte char
    return chr(($charcode >> 0x6) + 0xc0) . chr(($charcode & 0x3f) + 128);
  }
  if ($charcode <= 0xffff) {

    // 3-byte char
    return chr(($charcode >> 0xc) + 0xe0) . chr(($charcode >> 0x6 & 0x3f) + 0x80) . chr(($charcode & 0x3f) + 0x80);
  }
  if ($charcode <= 0x1fffff) {

    // 4-byte char
    return chr(($charcode >> 0x12) + 0xf0) . chr(($charcode >> 0xc & 0x3f) + 0x80) . chr(($charcode >> 0x6 & 0x3f) + 0x80) . chr(($charcode & 0x3f) + 0x80);
  }

  // unidentified char code !!
  return ' ';
}