homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Can't get rid of query string trailing space
trim function doesn't work

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


I'm using my query like this:

$string = trim($_GET['query']);
$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?




 8:54 pm on May 16, 2005 (gmt 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));



 9:25 pm on May 16, 2005 (gmt 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)

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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved