使用无包装保存textarea会导致奇怪的字符到php

I have a textarea to user input a query. So i'm using this to prevent wrapping:

textarea{
    white-space:nowrap;
}

so, then I input a SQL like this

SELECT
   field1
FROM my table

This is correctly saved in mysql utf8_general_ci field, but when I try to var_dump() saved content, it shows:

SELECT
 Ã  Ã field1
FROM my table

If I remove css from textarea, it works fine. But I need no-wrap.

It appears that the browser is (poorly) implementing white-space:nowrap by silently converting all spaces to non-breaking spaces ( ).

This character is 0xA0 in single-byte character sets like ISO-8859-1 and Windows-1252.

However it is being sent encoded as UTF-8.

This character, when converted to UTF-8, happens to convert to the two-byte sequence 0xC2A0, which when "cast" back to single characters gives 0xC2 followed by 0xA0, or à followed by [NBSP] (it's mostly coincidental that the second byte is the same as the original character, don't take any meaning from it)

I would suggest using the older, more compatible way of disabling wrapping:

<textarea wrap="off">...</textarea>

This will disable wrapping, and you should stop seeing those strange characters.