开发者

Encoded characters ended up in my MySQL

I have an encoding issue - I have data stored in a MySQL table. While doing some work, one of my columns in my table collected some oblesks and negation signs; or the usual diamond w/ a question mark depending on the encoding. Rather than manually changing each row, is there a quick way to seek and destroy the characters from the DB?

I've played with both my browser settings as well as using UTF-8, Western 1252 and ISO-8859-1. I was happy with how the data was encoded before, I just want to remove the improperly encoded whatevers out of the DB. I tried writing a quick PHP script to grab all the chars and replace them, but I can't figure out what they even are. Any ideas?

Here ar开发者_如何学运维e the characters as seen in UTF-8 ¬†


I don't know if you can actually do this but

UPDATE `table` SET column = replace(column, REGEXP '[\x00-\x1F\x80-\xFF]', '');

Make sure you run this as a select first or do this in a temporary sandbox db. I dunno if this is legal in mysql.

I know there are third party regex libraries that can do this but require changing your db. I don't know how these work.

  • UDF

EDIT

You're better off writing a little php script to do this for you. The above regex will work to strip out garbage characters.

$data = preg_replace_all('/[\x00-\x1F\x80-\xFF]/', '', $data);

Once again, if it wasn't clear before: DO NOT BLINDLY PASTE IN MY ABOVE SQL STATEMENT as I have no idea what will actually happen.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜