Exemple #1
0
function linearHangul($str, $withOutJung = False)
{
    $cho = array("ㄱ", "ㄲ", "ㄴ", "ㄷ", "ㄸ", "ㄹ", "ㅁ", "ㅂ", "ㅃ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅉ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ");
    $jung = array("ㅏ", "ㅐ", "ㅑ", "ㅒ", "ㅓ", "ㅔ", "ㅕ", "ㅖ", "ㅗ", "ㅘ", "ㅙ", "ㅚ", "ㅛ", "ㅜ", "ㅝ", "ㅞ", "ㅟ", "ㅠ", "ㅡ", "ㅢ", "ㅣ");
    $jong = array("", "ㄱ", "ㄲ", "ㄳ", "ㄴ", "ㄵ", "ㄶ", "ㄷ", "ㄹ", "ㄺ", "ㄻ", "ㄼ", "ㄽ", "ㄾ", "ㄿ", "ㅀ", "ㅁ", "ㅂ", "ㅄ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅊ", "ㅋ", " ㅌ", "ㅍ", "ㅎ");
    $result = array();
    for ($i = 0; $i < utf8_strlen($str); $i++) {
        $code = utf8_ord(utf8_charAt($str, $i)) - 44032;
        if ($code > -1 && $code < 11172) {
            $cho_idx = $code / 588;
            $jung_idx = $code % 588 / 28;
            $jong_idx = $code % 28;
            if ($withOutJung) {
                /*
                				if($jong_idx == 0) {
                array_push($result, $cho[$cho_idx]);
                				} else {
                */
                array_push($result, $cho[$cho_idx], $jong[$jong_idx]);
                /*
                $result[$i][0] = $cho[$cho_idx];
                $result[$i][1] = $jong[$jong_idx];
                */
                //}
            } else {
                /*
                				if($jong_idx == 0) {
                array_push($result, $cho[$cho_idx], $jung[$jung_idx]);
                				} else {
                */
                array_push($result, $cho[$cho_idx], $jung[$jung_idx], $jong[$jong_idx]);
                /*
                $result[$i][0] = $cho[$cho_idx];
                $result[$i][1] = $jung[$jung_idx];
                $result[$i][2] = $jong[$jong_idx];
                */
                //}
            }
        }
    }
    return $result;
}
 /**
  * Generate the captcha question
  *
  * @return string The question string
  */
 protected function getQuestion()
 {
     $int1 = rand(1, 9);
     $int2 = rand(1, 9);
     $question = $GLOBALS['TL_LANG']['SEC']['question' . rand(1, 3)];
     $question = sprintf($question, $int1, $int2);
     $this->Session->set('captcha_' . $this->strId, array('sum' => $int1 + $int2, 'key' => $this->strCaptchaKey, 'time' => time()));
     $strEncoded = '';
     $arrCharacters = utf8_str_split($question);
     foreach ($arrCharacters as $strCharacter) {
         $strEncoded .= sprintf('&#%s;', utf8_ord($strCharacter));
     }
     return $strEncoded;
 }
Exemple #3
0
/**
* Takes a UTF-8 char and replaces it with its unicode escape sequence. Attention, $m is an array
*
* @param	array	$m			0-based numerically indexed array passed by preg_replace_callback()
* @return	string				A unicode escape sequence
*/
function utf8_to_unicode_callback($m)
{
    return '\\u' . str_pad(base_convert(utf8_ord($m[0]), 10, 16), 4, '0', STR_PAD_LEFT) . '';
}
Exemple #4
0
/**
 * 用于 encode_ncr() 的回调函数
 */
function utf8_to_ncr_callback($m)
{
    return '&#' . utf8_ord($m[0]) . ';';
}
Exemple #5
0
 /**
  * @dataProvider providerFailingUtf8Ord
  */
 public function testFailingUtf8OrdReturnValue($str)
 {
     $this->assertFalse(@utf8_ord($str));
 }
/**
 * utf8_range( )
 * 
 * Create an array containing a range of UTF-8 characters
 * @since 1.2
 * 
 * @param    mixed $var1 Numeric or hexadecimal code points, or a UTF-8 character to start from
 * @param    mixed $var2 Numeric or hexadecimal code points, or a UTF-8 character to end at
 * @return   array Array of UTF-8 characters
 */
function utf8_range($var1, $var2)
{
    if (ctype_digit((string) $var1)) {
        $start = (int) $var1;
    } else {
        if (!($start = (int) utf8_hex_to_int($var1))) {
            //if not u+0000 style codepoint
            if (!($start = utf8_ord($var1))) {
                //if not a valid utf8 character
                return array();
            }
        }
    }
    if (ctype_digit((string) $var2)) {
        $end = (int) $var2;
    } else {
        if (!($end = (int) utf8_hex_to_int($var2))) {
            //if not u+0000 style codepoint
            if (!($end = utf8_ord($var1))) {
                //if not a valid utf8 character
                return array();
            }
        }
    }
    return array_map('utf8_chr', range($start, $end));
}
 /**
  * UTF-8 aware alternative to ord()
  *
  * Returns the unicode ordinal for a character.
  *
  * @param   string  $chr  UTF-8 encoded character
  *
  * @return  integer Unicode ordinal for the character
  *
  * @see     http://www.php.net/ord
  * @since   1.4.0
  */
 public static function ord($chr)
 {
     return utf8_ord($chr);
 }
Exemple #8
0
 /**
  * Encode all e-mail addresses within a string
  *
  * @param string $strString The string to encode
  *
  * @return string The encoded string
  */
 public static function encodeEmail($strString)
 {
     $arrEmails = array();
     preg_match_all('/\\w([-.+!#$%&\'*\\/=?^`{}|~\\w]*\\w)?@\\w([-.\\w]*\\w)?\\.\\w{2,63}/u', $strString, $arrEmails);
     foreach ((array) $arrEmails[0] as $strEmail) {
         $strEncoded = '';
         $arrCharacters = utf8_str_split($strEmail);
         foreach ($arrCharacters as $strCharacter) {
             $strEncoded .= sprintf(rand(0, 1) ? '&#x%X;' : '&#%s;', utf8_ord($strCharacter));
         }
         $strString = str_replace($strEmail, $strEncoded, $strString);
     }
     return str_replace('mailto:', '&#109;&#97;&#105;&#108;&#116;&#111;&#58;', $strString);
 }
Exemple #9
0
 function test4ByteChar()
 {
     $str = "𐌼";
     $this->assertEqual(utf8_ord($str), 66364);
 }
Exemple #10
0
<tr class="row<?php 
    echo $i % 2;
    ?>
" >
	<td><?php 
    echo sprintf("%04d", $i);
    ?>
</td>
	<td><?php 
    echo sprintf("U+%04X", $i);
    ?>
</td>
	<td><?php 
    echo sprintf("&#x%02X;", $i);
    ?>
</td>
	<td><?php 
    echo utf8_ord($i);
    ?>
</td>
	<td><?php 
    echo print_utf8($i);
    ?>
</td>
</tr>
<?php 
}
?>
</table>
</body>
</html>