Welcome to WebmasterWorld Guest from 23.22.140.143

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Can't get rid of query string trailing space

trim function doesn't work

     
7:49 pm on May 16, 2005 (gmt 0)

New User

10+ Year Member

joined:Feb 11, 2004
posts:38
votes: 0


Hi

I'm using my query like this:

if(isset($_GET['query']))
{
$string = trim($_GET['query']);
}
else
{
$string = '';
}

$search_string = quote_smart($string);

function quote_smart($value)
{
// Stripslashes
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
//Quote if not integer
if (!is_numeric($value)) {
$value = mysql_real_escape_string($value);
}
return $value;
}

This works fine most of the time, but if I add a space to the end of the query such as "olive oil " it doesn't get trimmed and goes out to the browser as "olive+oil+" which crashes the browser. I've tried replacing the + and chopping it as well as seeing if it's being converted to '%2B', but to no avail. Does anyone know why the query isn't being trimmed?

Thanks

8:54 pm on May 16, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 30, 2003
posts:3719
votes: 0


I tried your code and the trim worked ok. I added a couple of spaces after and they both got stripped.

Try trimming when you return the value:

return trim(rawurlencode($value));

dc

9:25 pm on May 16, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 26, 2003
posts:1133
votes: 0


First of all you cannot have spaces in url, so that's why you don't have them in GET. Space in html is %20 and it may be that, that is causing you trouble. This sign (%20) is then translated to normal space, but in GET you still trim it. The idea might be to convert all %20 to spaces and then trimming them. However I never tried that.

Hope this helps you somehow
Best regards
Michal Cibor

2:21 am on May 28, 2005 (gmt 0)

New User

10+ Year Member

joined:Feb 11, 2004
posts:38
votes: 0


Thanks for your help. I've finally figured out it was the way I've been outputting the the browser that caused this. There has been an 'id' name clash, and all I needed to do was to rename uniquely.