mysql DB Collation이 UTF-8 이었는데, 서비스에서 이모티콘을 입력하니,
데이터 손실이 발생하였다.
예를 들면..
emoji + string -> empty
string1 + emoji + string2 -> string1
데이터 손실을 막기 위해서 아래와같은 정규식으로 이모티콘을 삭제시켰다.
$emojiPattern = '/[\\x{10000}-\\x{1FFFF}]/u';
function removeEmoji($content) {
return preg_replace($emojiPattern, '', $content);
}
이모티콘 데이터를 지원하기 위해서는 utf8mb4 형식을 사용해야 한다.
DBA가 콜레이션을 변경해주었고..
테스트를 해보았더니 이모티콘 영역은 ????? 로 깨져버린다.
왜 이런 현상이 일어나는 것인지 확인중..
----------------------------------------------------------------------------------------------
When I enter emoji to Mysql DB with collation utf-8, It makes data lose.
ex)
emoji + string -> empty
string1 + emoji + string2 -> string1
To prevent losing data, I removed emoji with below regular expression.
$emojiPattern = '/[\\x{10000}-\\x{1FFFF}]/u';
function removeEmoji($content) {
return preg_replace($emojiPattern, '', $content);
}
To support using emoji, have to change collation.(utf-8 => utf8mb4)
DBA changed collation.. but, when I tested, emoji converted to question mark..
댓글
댓글 쓰기