Humpty Posted March 2, 2006 Share Posted March 2, 2006 [b]*** SOLVED *** (thanks to Ken)[/b](still can't work out how to mark this as solved)G'day GuysI am echoing a PHP string in HTML that is a URL.Once that string is clicked on it passes info ($_GET) to the next PHP file. But somewhere between the file GETing the data and the file performing a query I lose a + (plus sign) that is in the field requirement.e.g:PHP:$MyString="productnumber+11kk";HTML:<? echo "$MyString" ?>The link:filename.php?datatoget=productnumber+11kk$_GET: When i use:$MyString2=$_GET['datatoget'];I end up withe $MyString2 storing "productnumber 11kk" and not "productnumber+1kk"The record in the query has the plus sign in it. (after all that is where the original $Mystrng actually comes from)Any ideas on how to stop the "+"(plus sign) turning into a " "(space character)...either by changing it before or the URL is displayed in href or after or while it is retrieved using the $_GET?Thanks - Humpty Quote Link to comment Share on other sites More sharing options...
willpower Posted March 2, 2006 Share Posted March 2, 2006 try adding a \ before the + Quote Link to comment Share on other sites More sharing options...
Humpty Posted March 2, 2006 Author Share Posted March 2, 2006 nah the \ didn't help.If anyone wants to fiddle with it the URL that it is is:"partnum=DVD+R50" <--- there is the offending + sign. even when you type into the browser it doesn't work." The rest of the URL is fine. Is just the + converts to a space (in my code that is).[a href=\"http://www.shop.teegee.net.au/ProductDetails.php?partnum=DVD+R50-16X&cat=DVDs%20and%20CDs&cat2=DVD-R//RW%20Media&cat3=\" target=\"_blank\"]http://www.shop.teegee.net.au/ProductDetai...W%20Media&cat3=[/a] Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 2, 2006 Share Posted March 2, 2006 Unfortunately, a plus sign is translated into a space by urldecode() which is implicitly called for you. What you need to do is apply the function urlencode() to the string before putting it into the URL.Example:[code]<?phpif (issset($_GET['test'])) echo '<pre>'.print_r($_GET,true).'</pre>';$plus = 'This string has a plus (+) sign in it.';$plus1 = urlencode($plus);<a href="<?php echo $_SERVER['PHP_SELF'] ?>?test=<?php echo $plus ?>">Test 1</a><br /><a href="<?php echo $_SERVER['PHP_SELF'] ?>?test=<?php echo $plus1 ?>">Test 2</a>?>[/code]Ken Quote Link to comment Share on other sites More sharing options...
Humpty Posted March 3, 2006 Author Share Posted March 3, 2006 G'day Ken,I thought it didn't work but I was wrongpffft......who am I to doubt you.You rock thankyou very much will remember that for next time. 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.