Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Parse problem.

Question posted by: mark (Guest) on July 16th, 2005 10:50 PM
I have a problem that php removes the + char. When i type this in the
adres bar:
http://www.test.com/test.php?t=a+b

and when i do a echo in the php page the + char is gone? I also tried
to use the javascript escape function before redirecting but that
won't work eather.

Can someone explein what i'm doing wrong? And how to post a + char ina
other way or something like that..

thanks
mark
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
Bert's Avatar
Bert
Guest
n/a Posts
July 16th, 2005
10:50 PM
#2

Re: Parse problem.
On 18 Jul 2003 02:46:50 -0700, Join Bytes! (mark) wrote:
[color=blue]
>I have a problem that php removes the + char. When i type this in the
>adres bar:
>http://www.test.com/test.php?t=a+b
>
>and when i do a echo in the php page the + char is gone? I also tried
>to use the javascript escape function before redirecting but that
>won't work eather.
>
>Can someone explein what i'm doing wrong? And how to post a + char ina
>other way or something like that..
>
>thanks
>mark[/color]

I found this in the php-manual:

To encode a '+' (plus) symbol so it ends up as '+' when decoded
automatically by PHP, you have to do this:

rawurlencode(rawurlencode("+"));

If you just call rawurlencode() once, the resulting "%2B" is converted
to '+' before '+' symbols are converted to spaces, which is not very
useful.

Give it a try...
B.


Jim Dabell's Avatar
Jim Dabell
Guest
n/a Posts
July 16th, 2005
10:50 PM
#3

Re: Parse problem.
mark wrote:
[color=blue]
> I have a problem that php removes the + char. When i type this in the
> adres bar:
> http://www.test.com/test.php?t=a+b
>
> and when i do a echo in the php page the + char is gone?[/color]

You are not sending a + character to the script. You are sending a space to
the script. Special characters like spaces get encoded so that they are
safe for transport across HTTP. Your script is seeing the data you sent
it, not the raw encoded form.

When you create links with non-hardcoded data in the query string, make sure
you run urlencode() over the data you are supplying:

echo("http://www.example.com/test.php?t=" . urlencode($data));

(Also, somebody owns the test.com domain, example.com is reserved
specifically for this purpose).

[color=blue]
> I also tried
> to use the javascript escape function before redirecting but that
> won't work eather.[/color]

Client-side scripting is unreliable. Plenty of people have javascript
unavailable, for all sorts of reasons.


--
Jim Dabell


 
Not the answer you were looking for? Post your question . . .
169,970 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors