For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > September 2005 > Passing '+' gives trouble.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Passing '+' gives trouble.
Mich

2005-09-30, 7:56 am

Hi all you experts,

I'm passing some text from one page to the other which holds a '+' in the
text:

$text = "regeling + formaat"

stap5.php?text=regeling%20+%20formaat

I can see this being passed in the URL bar, but my $_get doesn't pick it
fully up.
$_get['text'] gives me $text="regeling formaat"

Can anybody help me out?


Hilarion

2005-09-30, 7:56 am

> I'm passing some text from one page to the other which holds a '+' in the
> text:
>
> $text = "regeling + formaat"
>
> stap5.php?text=regeling%20+%20formaat


This link is bad. How did you made it?
You should do it like this:

$link = 'stap5.php?text=' . urlencode( $text );


> I can see this being passed in the URL bar, but my $_get doesn't pick it
> fully up.
> $_get['text'] gives me $text="regeling formaat"


Because plus sign in URLs means space. If you use "urlencode", then
the problem will not appear. One more thing: do not use "urlencode"
when passing values in <input> fields - use "htmlspecialchars"
instead. If you use "urlencode" in <input>, then you'll have to
"urldecode" it on the page which gets the data, which makes
script more messy and gives nothing better than "htmlspecialchars"
does.


Hilarion
Mich

2005-09-30, 7:56 am

"Hilarion" <hilarion@SPAM.op.SMIECI.pl> wrote in message
news:dhj4fo$fdc$1@news.onet.pl...
the[color=darkred]
>
> This link is bad. How did you made it?
> You should do it like this:
>
> $link = 'stap5.php?text=' . urlencode( $text );
>
>
>
> Because plus sign in URLs means space. If you use "urlencode", then
> the problem will not appear. One more thing: do not use "urlencode"
> when passing values in <input> fields - use "htmlspecialchars"
> instead. If you use "urlencode" in <input>, then you'll have to
> "urldecode" it on the page which gets the data, which makes
> script more messy and gives nothing better than "htmlspecialchars"
> does.
>
>
> Hilarion


This what the url in the browser displays, its not the code ;-)
stap5.php?text=regeling%20+%20formaat

Anyway, thank a lot Hilarion, got it all workin now!

Thumbs up!


Hilarion

2005-09-30, 6:56 pm

> > > I'm passing some text from one page to the other which holds a '+' in
>
> This what the url in the browser displays, its not the code ;-)
> stap5.php?text=regeling%20+%20formaat


I know and this URL is bad. I assumed you are generating the URL (your
code is doing this) basing on the code fragment you gave ($text =
"regeling + formaat"). In that case the code is wrong (it should use
"urlencode"). If it's not your code, then you have no good way
to fix the the values you are getting. In url parameter values
the "+" sign and "%20" code both mean space character. If someone
wants to pass "+" sign in the URL, he should encode it (or pass
it in <input> fields in a <form> submited by GET method - this
way it's the browser who is doing the value encoding, so you
do not have to "urlencode" it).


> Anyway, thank a lot Hilarion, got it all workin now!


I'm happy to hear that.


Hilarion
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com