[PHP] 문자열에서 이모지(Emojis) 제거 (remove emojis from string)

[PHP] 문자열에서 이모지(Emojis) 제거 (remove emojis from string)

PHPExcel 사용시 셀값에 이모지가 포함된 문자열이 들어가면 에러 발생.

현재로썬 문자열에서 이모지를 제거하거나 다른 문자로 치환하는 수 밖에 없는 듯.

아래 함수로 이모지 제거가 가능함.

function removeEmojis($s) { $regexList = [ // Enclosed Alphanumeric Supplement '/[\x{1F100}-\x{1F1FF}]/u', // Miscellaneous Symbols and Pictographs '/[\x{1F300}-\x{1F5FF}]/u', // Emoticons '/[\x{1F600}-\x{1F64F}]/u', // Transport and Map Symbols '/[\x{1F680}-\x{1F6FF}]/u', // Supplemental Symbols and Pictographs '/[\x{1F900}-\x{1F9FF}]/u', // Miscellaneous Symbols '/[\x{2600}-\x{26FF}]/u', // Dingbats '/[\x{2700}-\x{27BF}]/u' ]; $emojiRemovedString = $s; foreach ($regexList as $regexPattern) { $emojiRemovedString = preg_replace($regexPattern, '', $emojiRemovedString); } return $emojiRemovedString; }

from http://bloodguy.tistory.com/1119 by ccl(A) rewrite - 2021-10-21 18:00:26