Jump to content


This topic is now archived and is closed to further replies.


more problems with PHP string to HTML to $_GET to Query

Recommended Posts

[b]*** SOLVED *** (thanks to Ken)[/b]
(still can't work out how to mark this as solved)

G'day Guys

I 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.



<? echo "$MyString" ?>

The link:

$_GET: When i use:

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

Share this post

Link to post
Share on other sites
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]

Share this post

Link to post
Share on other sites
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.

if (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>


Share this post

Link to post
Share on other sites
G'day Ken,

I thought it didn't work but I was wrong

pffft......who am I to doubt you.

You rock thankyou very much will remember that for next time.

Share this post

Link to post
Share on other sites

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.