如何在没有额外空格的情况下从MySQL检索字符数据?

I am using a form to load text into a database. Then, I'm pulling the text back out with php in order to dynamically create my CSS selectors. Then I'm using javascript to toggle the selectors on and off as needed. Everything works well except the retrieved data has long lines of spaces in it (like the entire textarea of the form is included) and therefore, the javascript doesn't work due to the extra spaces. Because these are labels, they vary in length. I've tried storing the data as VARCHAR CHAR and TEXT. How can I retrieve only the characters from MySQL? I have seen it somewhere in the manual but can't seem to find it now. Thanks

You could just use trim in PHP. MySQL also has a TRIM().

Note that this removes all whitespace before and after the string, not space within the string.

You also will apparently always have a newline submitted because of the whitespace in the html itself. You should probably close the textarea without creating additional whitespace.

Do you just want to replace all white spaces?

REPLACE(col, ' ', '')

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_replace