인터넷정보

문자열 1바이트씩 배열에 담기

알 수 없는 사용자 2007. 12. 27. 13:15
캐릭터셋이 euc-kr 이라 전제하고

$temp_var = "a-_fa(#)^$*F&3i4-0한2글abc3국민 az?/a*&韓お手?ご迷惑をお掛けしました、";
$cnt = strlen($temp_var);
$array = array();
for($i = 0; $i < $cnt; $i++)
{
    if(ord($temp_var[$i]) < 128)
    {
        $array[] = $temp_var[$i];
    }
    else{
        $array[] = substr($temp_var, $i, 2);
        $i++;
    }
}

array
  0 => string 'a' (length=1)
  1 => string '-' (length=1)
  2 => string '_' (length=1)
  3 => string 'f' (length=1)
  4 => string 'a' (length=1)
  5 => string '(' (length=1)
  6 => string '#' (length=1)
  7 => string ')' (length=1)
  8 => string '^' (length=1)
  9 => string '$' (length=1)
  10 => string '*' (length=1)
  11 => string 'F' (length=1)
  12 => string '&' (length=1)
  13 => string '3' (length=1)
  14 => string 'i' (length=1)
  15 => string '4' (length=1)
  16 => string '-' (length=1)
  17 => string '0' (length=1)
  18 => string '한' (length=2)
  19 => string '2' (length=1)
  20 => string '글' (length=2)
  21 => string 'a' (length=1)
  22 => string 'b' (length=1)
  23 => string 'c' (length=1)
  24 => string '3' (length=1)
  25 => string '국' (length=2)
  26 => string '민' (length=2)
  27 => string ' ' (length=1)
  28 => string 'a' (length=1)
  29 => string 'z' (length=1)
  30 => string '?' (length=1)
  31 => string '/' (length=1)
  32 => string 'a' (length=1)
  33 => string '*' (length=1)
  34 => string '&' (length=1)
  35 => string '韓' (length=2)
  36 => string 'お' (length=2)
  37 => string '手' (length=2)
  38 => string '?' (length=1)
  39 => string 'ご' (length=2)
  40 => string '迷' (length=2)
  41 => string '惑' (length=2)
  42 => string 'を' (length=2)
  43 => string 'お' (length=2)
  44 => string '掛' (length=2)
  45 => string 'け' (length=2)
  46 => string 'し' (length=2)
  47 => string 'ま' (length=2)
  48 => string 'し' (length=2)
  49 => string 'た' (length=2)
  50 => string '、' (length=2)
반응형