작은숲:위키노트/EUC2UTF: 두 판 사이의 차이

큰숲백과, 나무를 보지 말고 큰 숲을 보라.
잔글 (문자열 찾아 바꾸기 - "분류:공유" 문자열을 "분류:위키노트/공유" 문자열로)
잔글 (문자열 찾아 바꾸기 - "<source" 문자열을 "<syntaxhighlight" 문자열로)
1번째 줄: 1번째 줄:
[[FreeFeel]] 이사 작업을 하면서 만들었던 [[위키노트:PHP|PHP]] 스크립트이다. EUC-KR로 운영되던 [[위키노트:위키|위키]]의 텍스트들을 UTF-8로 인코딩 변환을 시켜준다. 물론 텍스트 내용 뿐 아니라, 페이지 이름도 그에 맞게 변환한다.
[[FreeFeel]] 이사 작업을 하면서 만들었던 [[위키노트:PHP|PHP]] 스크립트이다. EUC-KR로 운영되던 [[위키노트:위키|위키]]의 텍스트들을 UTF-8로 인코딩 변환을 시켜준다. 물론 텍스트 내용 뿐 아니라, 페이지 이름도 그에 맞게 변환한다.
<source lang="php">
<syntaxhighlight lang="php">
#!/usr/bin/php
#!/usr/bin/php
<?php
<?php

2021년 3월 28일 (일) 12:51 판

FreeFeel 이사 작업을 하면서 만들었던 PHP 스크립트이다. EUC-KR로 운영되던 위키의 텍스트들을 UTF-8로 인코딩 변환을 시켜준다. 물론 텍스트 내용 뿐 아니라, 페이지 이름도 그에 맞게 변환한다. <syntaxhighlight lang="php">

  1. !/usr/bin/php

<?php $src_dir = "text.euc-kr"; $dest_dir = "text"; $src_charset = "euc-kr"; $dest_charset = "utf-8"; if (!is_dir($dest_dir)) {

   mkdir($dest_dir);
   chmod($dest_dir, 0777);

}if (!is_dir("$dest_dir/RCS")) {

   mkdir("$dest_dir/RCS");
   chmod("$dest_dir/RCS", 0777);

}$error_page = array(); if (is_dir($src_dir)) {

   if ($handle = opendir($src_dir)) {
       while (($file = readdir($handle)) != false) {
           //if ($file == "." or $file == "..") continue;
           if (preg_match("/^[\.|#]/", $file)) continue;
           if (is_dir("$src_dir/$file")) continue;
           $pagename = rawurldecode(strtr($file, '_', '%'));
           $new_pagename = iconv($src_charset, $dest_charset, $pagename);
           $new_file = preg_replace("/([^a-z0-9]{1})/ie",
                               "'_'.strtolower(dechex(ord('\\1')))", $new_pagename);
           //echo "$file -> $new_file\n";
           $command = "iconv -f $src_charset -t $dest_charset ".
                       "$src_dir/$file -o $dest_dir/$new_file";
           //echo "$command\n";
           system(escapeshellcmd($command), $ret);
           if ($ret != 0) {
               $error_page= $new_pagename;
               echo "Error: $new_file\n";
           }
           //continue;
           chmod("$dest_dir/$new_file", 0666);
           // rcs commit
           $tmp_pagename = escapeshellcmd($new_pagename);
           $log = "222.234.2.78;;mooo;;";
           $command = sprintf('ci -l -x,v/ -q -t="%s" -m="%s" %s/%s', $tmp_pagename, $log, $dest_dir, $new_file);
           system($command);
           chmod("$dest_dir/RCS/$new_file,v", 0666);
           //break;
           //if (count($error_page) > 10) break;
       }
       closedir($handle);
   }
   if (count($error_page)) {
       $fp = fopen("error-page", "w");
       foreach ($error_page as $page) {
           fwrite($fp, "$page\n");
       }
       fclose($fp);
   }

} // if (is_dir($src_dir)) // vim:et:sts=4 ?>

</source>

이 작은숲 문서의 출처는 위키노트의 위키노트/EUC2UTF 문서입니다.