php 에서 한글 그누보드면 그 에서 ㅡ 뺀 ㄱ 을 구할수 있을까요? 정보
php 에서 한글 그누보드면 그 에서 ㅡ 뺀 ㄱ 을 구할수 있을까요?본문
php 에서 한글 그누보드면 그 에서 ㅡ 뺀 ㄱ 을 구할수 있을까요?
댓글 전체
제 지식안에서는 조금 복잡하게 소스가 나올거 같습니다.
우선 데이터에서 첫번짜 글짜를 잘른후
그 글자를 str_replace 를 이용해 변환후 출력해야 할거 같습니다.
우선 데이터에서 첫번짜 글짜를 잘른후
그 글자를 str_replace 를 이용해 변환후 출력해야 할거 같습니다.
str_replace 함수를 써볼라고 했더니 한글이 너무 많네요 --
자바스크립으로 가능할거 같은데 찾아봐도 안나오네요.
자바스크립으로 가능할거 같은데 찾아봐도 안나오네요.
인코딩파일이 ansi 일때만 적용되는 소스이네요
수정해 쓰시면됩니다.
<?php
function GetUtf8String($str) {
$arr_cho = array(
"ㄱ", "ㄲ", "ㄴ", "ㄷ", "ㄸ", "ㄹ", "ㅁ",
"ㅂ", "ㅃ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅉ",
"ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ");
$arr_jung = array(
"ㅏ", "ㅐ", "ㅑ", "ㅒ", "ㅓ", "ㅔ", "ㅕ",
"ㅖ", "ㅗ", "ㅘ", "ㅙ", "ㅚ", "ㅛ", "ㅜ",
"ㅝ", "ㅞ", "ㅟ", "ㅠ", "ㅡ", "ㅢ", "ㅣ");
$arr_jong = array(
"", "ㄱ", "ㄲ", "ㄳ", "ㄴ", "ㄵ", "ㄶ",
"ㄷ", "ㄹ", "ㄺ", "ㄻ", "ㄼ", "ㄽ", "ㄾ",
"ㄿ", "ㅀ", "ㅁ ", "ㅂ", "ㅄ", "ㅅ", "ㅆ",
"ㅇ", "ㅈ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ");
$unicode = array();
$values = array();
$lookingFor = 1;
for ($i = 0; $i < strlen( $str ); $i++ ) {
$thisValue = ord( $str[ $i ] );
if ( $thisValue < 128 ) {
$unicode[] = $thisValue;
} else {
if ( count($values)==0) $lookingFor = ($thisValue<224) ? 2 : 3;
$values[] = $thisValue;
if (count($values)==$lookingFor) {
$number = ($lookingFor==3) ? (($values[0]%16)*4096) + (($values[1]%64)*64) + ($values[2]%64) : (($values[0]%32)*64)+($values[1]%64);
$unicode[] = $number;
$values = array();
$lookingFor = 1;
}
}
}
$splitStr = '';
while (list($key, $code) = each($unicode)) {
if ($code>=44032 && $code<=55203) {
$temp = $code-44032;
$cho = (int)($temp/21/28);
$jung = (int)(($temp%(21*28)/28));
$jong = (int)($temp%28);
$splitStr.= $arr_cho[$cho].$arr_jung[$jung].$arr_jong[$jong];
} else {
$temp = array($unicode[$key]);
foreach($temp as $ununicode) {
if ( $ununicode<128) {
$splitStr.= chr($ununicode);
} elseif ($ununicode<2048) {
$splitStr.= chr(192+(($ununicode-($ununicode%64))/64));
$splitStr.= chr(128+($ununicode%64));
} else {
$splitStr.= chr(224+(($ununicode-($ununicode%4096))/4096));
$splitStr.= chr(128+((($ununicode%4096)-($ununicode%64))/64));
$splitStr.= chr(128+($ununicode%64));
}
}
}
}
$splitStr = str_replace(' ','',$splitStr);
return $splitStr;
}
// UTF-8 문자열 생성
$str = iconv('euc-kr','utf-8','이곳내요을 초성 중성 종성으로 분리해줍니다.);
echo GetUtf8String($str);
?>
수정해 쓰시면됩니다.
<?php
function GetUtf8String($str) {
$arr_cho = array(
"ㄱ", "ㄲ", "ㄴ", "ㄷ", "ㄸ", "ㄹ", "ㅁ",
"ㅂ", "ㅃ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅉ",
"ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ");
$arr_jung = array(
"ㅏ", "ㅐ", "ㅑ", "ㅒ", "ㅓ", "ㅔ", "ㅕ",
"ㅖ", "ㅗ", "ㅘ", "ㅙ", "ㅚ", "ㅛ", "ㅜ",
"ㅝ", "ㅞ", "ㅟ", "ㅠ", "ㅡ", "ㅢ", "ㅣ");
$arr_jong = array(
"", "ㄱ", "ㄲ", "ㄳ", "ㄴ", "ㄵ", "ㄶ",
"ㄷ", "ㄹ", "ㄺ", "ㄻ", "ㄼ", "ㄽ", "ㄾ",
"ㄿ", "ㅀ", "ㅁ ", "ㅂ", "ㅄ", "ㅅ", "ㅆ",
"ㅇ", "ㅈ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ");
$unicode = array();
$values = array();
$lookingFor = 1;
for ($i = 0; $i < strlen( $str ); $i++ ) {
$thisValue = ord( $str[ $i ] );
if ( $thisValue < 128 ) {
$unicode[] = $thisValue;
} else {
if ( count($values)==0) $lookingFor = ($thisValue<224) ? 2 : 3;
$values[] = $thisValue;
if (count($values)==$lookingFor) {
$number = ($lookingFor==3) ? (($values[0]%16)*4096) + (($values[1]%64)*64) + ($values[2]%64) : (($values[0]%32)*64)+($values[1]%64);
$unicode[] = $number;
$values = array();
$lookingFor = 1;
}
}
}
$splitStr = '';
while (list($key, $code) = each($unicode)) {
if ($code>=44032 && $code<=55203) {
$temp = $code-44032;
$cho = (int)($temp/21/28);
$jung = (int)(($temp%(21*28)/28));
$jong = (int)($temp%28);
$splitStr.= $arr_cho[$cho].$arr_jung[$jung].$arr_jong[$jong];
} else {
$temp = array($unicode[$key]);
foreach($temp as $ununicode) {
if ( $ununicode<128) {
$splitStr.= chr($ununicode);
} elseif ($ununicode<2048) {
$splitStr.= chr(192+(($ununicode-($ununicode%64))/64));
$splitStr.= chr(128+($ununicode%64));
} else {
$splitStr.= chr(224+(($ununicode-($ununicode%4096))/4096));
$splitStr.= chr(128+((($ununicode%4096)-($ununicode%64))/64));
$splitStr.= chr(128+($ununicode%64));
}
}
}
}
$splitStr = str_replace(' ','',$splitStr);
return $splitStr;
}
// UTF-8 문자열 생성
$str = iconv('euc-kr','utf-8','이곳내요을 초성 중성 종성으로 분리해줍니다.);
echo GetUtf8String($str);
?>
곰순이푸님 감사함니다. 아까 푸님 남기신 글 보고 열씨미 다시 영감 얻어서 뒤져보니 자바스크립트로 된 소스가 있더라구요. 해결 보았습니다. 감사^^ 곰순이님 소스가 더 알기 쉽네요. 이걸루 활용 해봐야 겠습니다. 감사함니다