KSC5601
[ class tree: KSC5601 ] [ index: KSC5601 ] [ all elements ]

Sample codes of KSC5601 class

  1. <?php
  2. error_reporting (E_ALL & ~E_NOTICE);
  3. function mtime($old, $new) {
  4.     $start = explode(" ", $old);
  5.     $end = explode(" ", $new);
  6.  
  7.     return sprintf("%.2f", ($end[1] + $end[0]) - ($start[1] + $start[0]));
  8. }
  9. function pr ($title, $msg) {
  10.     printf ("%-6s => %s\n", $title, $msg);
  11. }
  12.  
  13. $time1 = microtime ();
  14.  
  15. $cli = ( php_sapi_name () == 'cli' ) ? true : false;
  16.  
  17. if ( $cli !== true ) {
  18.     header('Content-Type: text/html');
  19.     echo "<pre>";
  20. }
  21.  
  22. if ( file_exists ('../KSC5601.php') ) {
  23.     # 하위 디렉토리에 KSC5601.php 가 존재할 경우, source tree에서의 테스트로
  24.     # 간주하여, include_path에 현재 디렉토리의 파일을 가장 우선시 시키고,
  25.     # 하위 디렉토리로 이동
  26.     $path = ini_get ('include_path');
  27.     $path = '.:' . $path;
  28.     ini_set ('include_path', $path);
  29.  
  30.     chdir ('..');
  31. }
  32.  
  33. require_once 'KSC5601.php';
  34.  
  35.  
  36. /*
  37.  * TEST CODE START
  38.  */
  39.  
  40.  
  41. $obj = new KSC5601;
  42.  
  43. # 표시할 수 없는 KSX1001 범위 밖의 문자 (CP949/UHC 확장 영역) 를 
  44. # NCR code 로 변경 한다.
  45. #$obj->out_of_ksx1001 (true);
  46.  
  47. $t1 = microtime ();
  48. $ksc = file_get_contents ('./test/test.txt');
  49.  
  50. pr ('원문', $ksc);
  51. $t2 = microtime ();
  52. echo "=>  " . mtime ($t1, $t2) . " sec\n";
  53.  
  54. if ( $obj->is_utf8 ($ksc) )
  55.     echo "yes\n";
  56. else
  57.     echo "no\n";
  58.  
  59. /*
  60.  * Convert EUC-KR(or UHC/CP949) to UTF8
  61.  */
  62. $t1 = microtime ();
  63. $utf = $obj->utf8 ($ksc, UTF8);
  64.  
  65. pr ('UTF8', $utf);
  66. $t2 = microtime ();
  67. echo "=>  " . mtime ($t1, $t2) . " sec\n";
  68.  
  69. /*
  70.  * Convert UTF8 to UHC/CP949
  71.  *
  72.  * todo : utf8 -> UHC/CP949 처리
  73.  *
  74.  */
  75. $t1 = microtime ();
  76. $ksc1 = $obj->utf8 ($utf, EUCkR);
  77.  
  78. pr ('KSC', $ksc1);
  79. $t2 = microtime ();
  80. echo "=>  " . mtime ($t1, $t2) . " sec\n";
  81.  
  82. /*
  83.  * convert EUC-KR (or UHC/CP949) to UCS2
  84.  */
  85. $t1 = microtime ();
  86. $ucs = $obj->ucs2 ($ksc, UCS2);
  87.  
  88. pr ('UCS2', $ucs);
  89. $t2 = microtime ();
  90.  
  91. /*
  92.  * convert UCS2 to UHC/CP949
  93.  */
  94. $t1 = microtime ();
  95. $ducs = $obj->ucs2 ($ucs, UHC);
  96.  
  97. pr ('DUCS2', $ducs);
  98. $t2 = microtime ();
  99. echo "=>  " . mtime ($t1, $t2) . " sec\n";
  100.  
  101. /*
  102.  * conver EUC-KR (or UHC/CP949) to NCR
  103.  */
  104. $t1 = microtime ();
  105. $ncr = $obj->ncr ($ksc, NCR);
  106.  
  107. pr ('NCR', $ncr);
  108. $t2 = microtime ();
  109. echo "=>  " . mtime ($t1, $t2) . " sec\n";
  110.  
  111. /*
  112.  * convert NCR to UHC/CP949
  113.  */
  114. $t1 = microtime ();
  115. $dncr = $obj->ncr ($ncr, UHC);
  116.  
  117. pr ('DNCR', $dncr);
  118. $t2 = microtime ();
  119. echo "=>  " . mtime ($t1, $t2) . " sec\n";
  120.  
  121.  
  122. #$z = utf8encode_lib ($ksc);
  123. #$z = utf8decode_lib ($z, 'cp949');
  124. #pr ('TEMP', $z);
  125. #echo uniencode_lib ($ksc, 'U+') . "\n";
  126. #echo unidecode_lib ($ucs, 'euc-kr', 'U+') . "\n";
  127.  
  128. /*
  129.  * substr UTF8
  130.  */
  131. $string = "2012.08.09 부터 OOPS에 무상 지원";
  132.  
  133. pr ('--                      ', " |123456789|123456789|123456789|12345 ");
  134. pr ('원문                    ', '\'' . $string . '\'');
  135. pr ('substr ($s, 0, 26)      ', '\'' . substr ($string, 0, 26) . '\'');
  136. pr ('obj->substr ($s, 0, 26) ', '\'' . $obj->substr ($string, 0, 26) . '\'');
  137. pr ('substr ($s, 0, 16)      ', '\'' . substr ($string, 0, 16) . '\'');
  138. pr ('obj->substr ($s, 0, 16) ', '\'' . $obj->substr ($string, 0, 16) . '\'');
  139. pr ('substr ($s, 22, 26)     ', '\'' . substr ($string, 22, 26) . '\'');
  140. pr ('obj->substr ($s, 22, 26)', '\'' . $obj->substr ($string, 22, 26) . '\'');
  141. pr ('substr ($s, 14, 10)     ', '\'' . substr ($string, 14, 10) . '\'');
  142. pr ('obj->substr ($s, 14, 10)', '\'' . $obj->substr ($string, 14, 10) . '\'');
  143. pr ('substr ($s, -8, 6)      ', '\'' . substr ($string, -8, 6) . '\'');
  144. pr ('obj->substr ($s, -8, 6) ', '\'' . $obj->substr ($string, -8, 6) . '\'');
  145. echo "\n";
  146.  
  147. $time2 = microtime ();
  148.  
  149. echo "=>  " . mtime ($time1, $time2) . " sec\n";
  150.  
  151. ?>

Documentation generated on Fri, 30 Aug 2024 06:10:34 +0900 by phpDocumentor 1.4.4