Jump to content

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.

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
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]
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]<?php
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>
?>[/code]

Ken
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.