Welcome to WebmasterWorld Guest from 23.22.250.113

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Can't get rid of query string trailing space

trim function doesn't work

     

Snookered

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

10+ Year Member



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

dreamcatcher

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

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



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

mcibor

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

WebmasterWorld Senior Member 10+ Year Member



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

Snookered

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

10+ Year Member



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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month