ukweb Posted August 5, 2009 Share Posted August 5, 2009 Hi all I have constructed for a client a vehicle search engine. If a make is defined it obviously searches by make, and works as expected. However, I have a form which unsets the make variable so that the results can be returned without the make, and also works... providing there is no spaces in the makes name! it works by passing a variable in the url called 'rem' and if 'rem=make' it unsets the make variable, but when there are spaces it does unset it, but it doesn't remove the 'make=blah blah' from the $new_return variable... Here's my code: // If Make is to be unset... if ($_GET['rem'] == 'make') { $this_make = str_replace(' ', '+', $_GET['make']); $this_make = str_replace('%20', '+', $_GET['make']); list($new_return1,$new_return2) = explode('&make='.$this_make,$new_return); $new_return = $new_return1.$new_return2; list($new_return1,$new_return2) = explode('&rem='.$_GET['rem'],$new_return); $new_return = $new_return1.$new_return2; unset($_GET['make']); } I hope this makes sense! ANY help would be received with gratitude. Quote Link to comment Share on other sites More sharing options...
trq Posted August 5, 2009 Share Posted August 5, 2009 Spaces are not valid within a url. Use url_encode and url_decode. Quote Link to comment Share on other sites More sharing options...
ukweb Posted August 5, 2009 Author Share Posted August 5, 2009 Spaces are not valid within a url. Use url_encode and url_decode. Ok, using urldecode has helped, and I have rewritten the code so it reads: $this_model = urldecode($_GET['model']); $this_model = str_replace(' ', '+', $this_model); $new_return = str_replace('model='.$this_model, '', $new_return); $new_return = str_replace('rem=model', '', $new_return); // URL cleaning $new_return = str_replace('&&', '&', $new_return); $new_return = str_replace('=&', '=', $new_return); print $new_return; // debugging unset($_GET['model']); This works ok, but doesn't if an '&' is left at the end of $new_return. Does anyone know how to do this: if (last character of string $new_return == '&') { remove '&' from end of $new_return } thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.