HOME   ·Î±×ÀΠ  ȸ¿ø°¡ÀÔ
    
ȸ¿ø°¡ÀÔ
ºñ¹Ð¹øÈ£ ã±â ÀÚµ¿·Î±ä
ÀÌÀü°Ô½ÃÆÇ
   free_board
   °Ç°­°Ô½ÃÆÇ
   ¿À¶óŬDB
   Linux
   HTML/javascript
   Áú¹®°ú ´ä
È£¼­±â
   À̹ÌÁö°Ô½ÃÆÇ  
   °Ç°­°Ô½ÃÆÇ  
   À½¾ÇÀÚ·á  
   ¼ºÁØÀÌ °Ô½ÃÆÇ  
  2010-06-02 20:24:131670 
converts a UTF8-string into HTML entities
È£¼®
ÀϹÝ
silverbeat -eat- gmx -hot- at
10-Mar-2010 05:42
When using UTF-8 as a charset, htmlentities will only convert 1-byte and 2-byte characters. Use this function if you also want to convert 3-byte and 4-byte characters:

<?php

// converts a UTF8-string into HTML entities
//  - $utf8:        the UTF8-string to convert
//  - $encodeTags:  booloean. TRUE will convert "<" to "<"
//  - return:       returns the converted HTML-string
function utf8tohtml($utf8, $encodeTags) {
    $result = '';
    for ($i = 0; $i < strlen($utf8); $i++) {
        $char = $utf8[$i];
        $ascii = ord($char);
        if ($ascii < 128) {
            // one-byte character
            $result .= ($encodeTags) ? htmlentities($char) : $char;
        } else if ($ascii < 192) {
            // non-utf8 character or not a start byte
        } else if ($ascii < 224) {
            // two-byte character
            $result .= htmlentities(substr($utf8, $i, 2), ENT_QUOTES, 'UTF-8');
            $i++;
        } else if ($ascii < 240) {
            // three-byte character
            $ascii1 = ord($utf8[$i+1]);
            $ascii2 = ord($utf8[$i+2]);
            $unicode = (15 & $ascii) * 4096 +
                       (63 & $ascii1) * 64 +
                       (63 & $ascii2);
            $result .= "&#$unicode;";
            $i += 2;
        } else if ($ascii < 248) {
            // four-byte character
            $ascii1 = ord($utf8[$i+1]);
            $ascii2 = ord($utf8[$i+2]);
            $ascii3 = ord($utf8[$i+3]);
            $unicode = (15 & $ascii) * 262144 +
                       (63 & $ascii1) * 4096 +
                       (63 & $ascii2) * 64 +
                       (63 & $ascii3);
            $result .= "&#$unicode;";
            $i += 3;
        }
    }
    return $result;
}

echo utf8tohtml($anyUTF8string, TRUE);

?>

regards, silverbeat
¸ñ·Ï
4814
¹øÈ£ ºÐ·ù Á¦¸ñ ¼º¸í ³¯Â¥ ÀÐÀ½
48 ÀÏ¹Ý jQuery¸¦ ¹è¿ï¼ö ÀÖ´Â µ¿³×µéÀÔ´Ï´Ù. È£¼® 14-03-03 2045
47 ÀÏ¹Ý PRO*C XML »ý¼º 󸮰ü·Ã È£¼® 13-03-07 1712
46 ÀÏ¹Ý jquery ¾ÆÀÛ½º Á¾ÇÕÁ¤¸® (1) È£¼® 12-08-17 1936
45 ÀÏ¹Ý ÀÚ¹Ù½ºÅ©¸³Æ® Ư¼ö¹®ÀÚ Ã¼Å©·ÎÁ÷ goood È£¼® 12-03-30 1759
44 ÀÏ¹Ý JSP¿¡¼­ iBATIS Framework »ç¿ëÇϱâ È£¼® 12-03-09 1761
43 ÀÏ¹Ý À¥ °³¹ßÀÚ¸¦ À§ÇÑ jQuery ±âº»ÀÌÇØ È£¼® 12-02-14 1667
42 ÀÏ¹Ý jQuery¿¡ ´ëÇؼ­ ùÁÙ¿¡ ³»Æ÷µÇ¾î ÀÖ´ÂÀÇ¹Ì È£¼® 11-08-04 1580
41 ÀÏ¹Ý ¸Þ´ºÄÁÆ®·ÑÀÌ ¾ð±ÞµÇ¾î Àִ°÷ È£¼® 11-08-04 1669
40 ÀÏ¹Ý Ckeditor ¼³Ä¡ ¹× ¼³Á¤ (1) È£¼® 11-08-04 1673
39 ÀÏ¹Ý HTML5ÀÇ ¸ðµç °Í È£¼® 11-07-06 1498
38 ÀÏ¹Ý CURL À» ÀÌ¿ëÇÑ GET/POST º¯¼ö Àü¼Û (2) È£¼® 11-06-21 1747
37 ÀÏ¹Ý jquery ¿¡´Ï¸ÞÀÌÆ® ±×·¡ÇÁ good ÁÁ¾Æ¿ä È£¼® 11-06-18 1687
36 ÀÏ¹Ý jjQuery Plugin Graph (±×·¡ÇÁ Ç÷¯±×ÀÎ) (1) È£¼® 11-05-27 1738
ÀÏ¹Ý converts a UTF8-string into HTML entities È£¼® 10-06-02 1671
34 ÀÏ¹Ý getElementById¿Í getElementByNameÀÇ Â÷ÀÌ È£¼® 10-02-18 2401
1 [2] [3] [4]  ´ÙÀ½¸Ç³¡
 
Copyright © zenos.pe.kr. All rights reserved.