douyi1341
2012-11-11 11:36
浏览 142
已采纳

如何删除mysql列中的空格

I have a column in a mysql table which has extra whitespaces on the end. Although i already tried to do REPLACE and TRIM within mysql and $output = preg_replace("/\s+/", " ", $input); nothing seems to remove the extra whitespace or whatever it is in the end of the string.

The column is a varchar(255) collation utf8_general_ci. It contains an alphanumeric string which represents a flight number e. g. LH2214. I have another column which also is the same collation and also varchar(255) with the same alphanumeric strings, which doesn't have the extra whitespace after it.

I only can see the whitespace on my webpage, which has charset utf-8. But what i can't see is, if it is a tabspace, whitespace, eol, eof or similar, so i don't know how to filter it out. Does anybody have any ideas how do i get rid of the extra whitespace in the end of the values in my column in mysql?

I already tried a lot of solutions posted to similar questions her on SO, but none worked.

I added an image to show my problem.

extra whitspace visible in the upper line.

The funny thing is, that in the source-code, there is no whitespace visible. So if I save the html, i will not see an whitespace nor an   or similar.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doude2635 2012-11-11 12:03
    已采纳

    Looks to me (from your screenshot), that you have some additional CSS properties on the rows that have the "additional whitespace". Take a look at your css properties, perhaps you set a margin, padding, text-indent or some other property that would shift your text/content.

    点赞 打赏 评论
  • dtntjwkl83750 2012-11-11 20:44

    Two possible reasons for the additional whitespace come to my mind.

    1. Trailing white-space characters are inserted into the table column.

    You can verify and fix this ( for existing data ) Using the following Query:

    UPDATE <your_table> SET <your_column> = TRIM ( <your_column> );
    

    If this worked you should have a confirmation 'n rows updated' with n > 0

    1. If this returned 0 rows updated you most likely have the whitespace added in your ouput.

    Check your output HTML and Stylesheets

    点赞 打赏 评论

相关推荐 更多相似问题