php - MySQL insert String error - UTF-8? -
i inserting mysql database. following error when trying insert
incorrect string value: '\xf0\x9f\x87\xb7\xf0\x9f...' column 'field_4' @ row 1
i thought had figured out error changing column encoding utf8mb4 , had tested error appeared again. using php parse string , run following function before inserting...
function strip_emoji($subject) { if (is_array($subject)) { // recursive strip multidimensional array foreach ($subject &$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 , pictographs $regexsymbols = '/[\x{1f300}-\x{1f5ff}]/u'; $clean_text = preg_replace($regexsymbols, '', $clean_text); // match transport , map symbols $regextransport = '/[\x{1f680}-\x{1f6ff}]/u'; $clean_text = preg_replace($regextransport, '', $clean_text); return }
there several similar questions still have these errors. further advice on how prevent error? realize emoji unicode character / sprite not sure how deal it.
do have utf8 charset connection well?
adding ";charset=utf8" in pdo-connection string, or executing query "set names utf8".
Comments
Post a Comment