사이트 내 전체검색
PHP
iconv 함수를 사용하지 못할경우, php 업그레이드,재컴파일이 불가능할경우 리눅스의 iconv 함수를 사용해서 실행 2009-11-03 김성대
로빈아빠
https://cmd.kr/php/280 URL이 복사되었습니다.

본문

 function iconv($from, $to, $text)
 {
  global $g4;
  if ($text) {
   //임시파일위치
   $iconv_prg = "/usr/bin/iconv";
   $tmp_file = "$g4[path]/tmp/tmp.".session_id();  //임시파일을 저장할 위치
  
   $p = popen($iconv_prg." --from-code=".$from." --to-code=".$to." --output=".$tmp_file, "w");
   if ($p) {
    fwrite($p, $text);
    pclose($p);
    
    $fp = fopen($tmp_file, "r");
    $text = fread($fp, filesize($tmp_file));
    fclose($fp);
    unlink($tmp_file);
   }
  }
  return $text;
 }

댓글들..
---------------------------

그냥

tar xvfpz php-version.tar.gz
cd php-version/ext/iconv
phpize
./conifgure
make
make install

해서 iconv extension 만 등록하는 것이 낳을 듯 싶은데요. 다만.. compiler 가 시스템에 없다면 문제이겠지만..

개인 적으로 iconv 명령을 이용할 것이라면 perl 의 piconv 를 이용하는 것이 낳다는 판단입니다. glibc 의 iconv 는 에러를 내며 뻗는 경우가 많은지라.. :-)

---------------------------
뭐 EUC-KR(UHC) <-> UTF-8 만 고려하면 된다면.. http://cvs.oops.org/?cvsroot=PHP-Module&module=pear_KSC5601 이런 것도 있습니다. php native code로 되어 있습니다. :-) test 디렉토리에 보시면 예제가 있습니다.
---------------------------


   function iconv($from, $to, $text)
{
global $iconv_path;

$process = proc_open(
$iconv_path." --from-code=".$from." --to-code=".$to,
array(array("pipe", "r"),array("pipe", "w")),
$pipes
);

fwrite($pipes[0],$text);
fclose($pipes[0]);

$result = '';
while (!feof($pipes[1]))
$result .= fgets($pipes[1], 024);
fclose($pipes[1]);

proc_close($process);

return $result;
}
=============================

댓글목록

등록된 댓글이 없습니다.

PHP
871 (11/18P)

Search

Copyright © Cmd 명령어 18.217.10.160