download this file: class.getcho.php view text/plain: class.getcho.php file encoding: EUC-KR [goback]
<?php
## file name 'class.getcho.php'
##
## Ãʼº ¾Ë¾Æ º¸±â
## Ãâó Àû¼ö³×
##
## [example]
##  $getcho = new getcho;
##  echo $getcho->show('some korean string');
##  /*** or ***/
##  echo $getcho->show('some korean string',1);
##

class getcho
{
  var 
$str$code$conv;

  function 
getcho()
  {
    
$this->code =
    array(
'b0a1' => '¤¡''b1ee' => '¤¡''b3aa' => '¤¤',
    
'b4d9' => '¤§''b5fb' => '¤§''b6f3' => '¤©',
    
'b8b6' => '¤±''b9d9' => '¤²''bafc' => '¤²',
    
'bbe7' => '¤µ''bdce' => '¤µ''bec6' => '¤·',
    
'c0da' => '¤¸''c2a5' => '¤¸''c2f7' => '¤º',
    
'c4ab' => '¤»''c5b8' => '¤¼''c6c4' => '¤½',
    
'c7cf' => '¤¾''c8ff' => '');

    for(
$i=0$i<count($this->code); $i++) {
        
$this->conv[] = key($this->code);
        
next($this->code);
    }
  }

  function 
codeconv($code)
  {
    for(
$i=0$i<count($this->code)-1$i++) {
        if(
$code >= $this->conv[$i] && $code $this->conv[$i+1])
        { return 
$this->conv[$i]; }
    }

    return;
  }

  function 
ishangul($char)
  {
    if(
ord($char) & 0x80) return 1;
  }

  function 
convert($str)
  {
    
$code bin2hex($str);
    
$code $this->codeconv($code);

    if(
$this->code[$code]) return $this->code[$code];
    else return 
$str;
  }

  function 
show($str$len=0)
  {
    if(!
$len || $len<=0$len strlen($str);

    for(
$i=0$i<$len$i++)
    {
        
$char substr($str,$i,1);

        if(
$this->ishangul($char)) {
            
$ret .= $this->convert(substr($str,$i,2));
            
$i++;
        } else {
            
$ret .= $char;
            
/***
            if(!preg_match('/[a-zA-Z]/',$char)) {
                echo 'À̸§Àº Çѱ۰ú [a-ZA-Z] »çÀ̾î¾ß ÇÕ´Ï´Ù.';
            } else {
                $ret .= strtoupper($char); // ´ë¹®ÀڷΠ¹Ù²Þ
            }
            ***/
        
}
    }

    return 
$ret;
  }
// end of class

?>