搜索后删除空格

I've just created a small search engine.. It works fine, but, whenever I search something up with a space on the end; it shows all contents that are in the database? How do I make it so that when people have a space at the end of their input field, it doesn't include that space. Thanks :)

Use trim() to trim spaces.

 str.trim() //Where str is the value of search field

Use trim on the filter input.

Php: http://php.net/trim

or

Javascript: http://www.w3schools.com/jsref/jsref_trim_string.asp