PHP 이모티콘 제거

개발공부 2017. 3. 7. 10:21
반응형


[PHP] How to remove the emoji

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..


반응형

'개발공부' 카테고리의 다른 글

Google Custom Search - Using REST to Invoke the API  (0) 2017.03.07
[javascript] href hashtag  (0) 2017.03.07
[linux] 우분투 자바 설치  (0) 2017.03.07
mac putty ppk 사용  (0) 2017.03.05
eclipse maven 셋팅  (0) 2017.03.05
posted by 알릿수