MySQL inserts String error - UTF-8?

I am inserting mysql into the database. When trying to paste

I get the following error:
Incorrect string value: '\xF0\x9F\x87\xB7\xF0\x9F...' for column 'field_4' at row 1

I thought I understood this error by simply changing the column encoding to utf8mb4 and tested, but recently this error has appeared again. I am using php to parse a string and run the following function before pasting ...

function strip_emoji($subject) {
    if (is_array($subject)) {
        // Recursive strip for multidimensional array
        foreach ($subject as &$value) $value = $this->strip_emoji($value);
        return $subject;
    } else {
        // Match Emoticons
        $regexEmoticons = '/[\x{1F600}-\x{1F64F}]/u';
        $clean_text = preg_replace($regexEmoticons, '', $subject);

        // Match Miscellaneous Symbols and Pictographs
        $regexSymbols = '/[\x{1F300}-\x{1F5FF}]/u';
        $clean_text = preg_replace($regexSymbols, '', $clean_text);

        // Match Transport And Map Symbols
        $regexTransport = '/[\x{1F680}-\x{1F6FF}]/u';
        $clean_text = preg_replace($regexTransport, '', $clean_text);
        return 
}

There are several similar questions, but I still have these errors. Any further recommendations on how to prevent this error? I understand that this is a character / sprite unoode from emoji, but not sure how to deal with it.

+4
source share
2 answers

, 4 , utf8mb4.

utf8 , 3 ( Unicode U + 0000 U + FFFF).

+1

utf8 ?

"; charset = utf8" PDO-connection utf8 ".

0

All Articles