从查询字符串php中删除加号

When user input space or nothing in the input bar, a plus sign + is still passed to my php backend. I would want to remove all plus signs before and after a word (e.g. return 'school' from '+++school++"). I see php have some nice function like strip_tag, but I am not sure what I should use in this case. Or is there a way to configure it (maybe through javascript?) so that those meaningless space/+ wouldn't even enter into the query string?

You can use:

$input = trim(urldecode($input));

where $input is one of the post parameters, such as: $input = $_POST["query"]; // if query was the POST parameter.

Edit: The other advantage of using urldecode is that it takes care of all other non alphanumeric characters that have been encoded.

From: http://php.net/manual/en/function.urldecode.php

$str = '++school++';
return trim(urldecode($str)

The + in the query string becomes a space in $_GET. All you need to do is trim leading and trailing spaces.

trim($_GET['param'])