How to remove bad characters that are not suitable for utf8 encoding in MySQL?

前端 未结 6 652
刺人心
刺人心 2020-12-16 13:05

I have dirty data. Sometimes it contains characters like this. I use this data to make queries like

WHERE a.address IN (\'mydatahere\')

For

6条回答
  •  鱼传尺愫
    2020-12-16 13:56

    In PHP - I approach this by only allowing printable data. This really helps in cleaning the data for DB.
    It's pre-processing though and sometimes you don't have that luxury.

    $str = preg_replace('/[[:^print:]]/', '', $str);
    

提交回复
热议问题