By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,823 Members | 730 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,823 IT Pros & Developers. It's quick & easy.

How to use escape characters (particularly #) with $_GET

P: n/a
I don't have a lot of experience using $_GET.

I need to know how to pass characters in using the $_GET method. The
character I'm having a problem with right now is '#', but I'm sure
there are others.

Could anyone give me a list of characters that need to be escaped
using $_GET, and then also how to use them?

Also, could you tell me if any characters simply are not allowed in a
get?

Example:

getData.php?type=edit&user=myName&item=Item#1

Thanks,

Chad

Mar 20 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
ch***********@gmail.com wrote:
I don't have a lot of experience using $_GET.

I need to know how to pass characters in using the $_GET method. The
character I'm having a problem with right now is '#', but I'm sure
there are others.

Could anyone give me a list of characters that need to be escaped
using $_GET, and then also how to use them?

Also, could you tell me if any characters simply are not allowed in a
get?

Example:

getData.php?type=edit&user=myName&item=Item#1

Thanks,

Chad
urlencode() your parameters.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Mar 20 '07 #2

P: n/a
On Mar 19, 8:45 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
chad.a.mor...@gmail.com wrote:
I don't have a lot of experience using $_GET.
I need to know how to pass characters in using the $_GET method. The
character I'm having a problem with right now is '#', but I'm sure
there are others.
Could anyone give me a list of characters that need to be escaped
using $_GET, and then also how to use them?
Also, could you tell me if any characters simply are not allowed in a
get?
Example:
getData.php?type=edit&user=myName&item=Item#1
Thanks,
Chad

urlencode() your parameters.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -

- Show quoted text -
I'm trying to go from javascript (making the call) to php.

For example:

function getData()
{
var user = "user1" ;
var item = encodeURI( "Item #1" ) ;
xmlHttp.open( 'GET' , 'addData.php?user=' + user + '&item=' +
item ) ;
}
However, the encodeURI() function on the string give returns the
following:

Item%20#1

So, it is leaving the pound sign, which is messing me up.

Any other thoughts? Perhaps I'm not using the functions correctly?

Thanks for the help!

Chad

Mar 20 '07 #3

P: n/a
ch***********@gmail.com wrote:
On Mar 19, 8:45 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>chad.a.mor...@gmail.com wrote:
>>I don't have a lot of experience using $_GET.
I need to know how to pass characters in using the $_GET method. The
character I'm having a problem with right now is '#', but I'm sure
there are others.
Could anyone give me a list of characters that need to be escaped
using $_GET, and then also how to use them?
Also, could you tell me if any characters simply are not allowed in a
get?
Example:
getData.php?type=edit&user=myName&item=Item#1
Thanks,
Chad
urlencode() your parameters.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -

- Show quoted text -

I'm trying to go from javascript (making the call) to php.

For example:

function getData()
{
var user = "user1" ;
var item = encodeURI( "Item #1" ) ;
xmlHttp.open( 'GET' , 'addData.php?user=' + user + '&item=' +
item ) ;
}
However, the encodeURI() function on the string give returns the
following:

Item%20#1

So, it is leaving the pound sign, which is messing me up.

Any other thoughts? Perhaps I'm not using the functions correctly?

Thanks for the help!

Chad
Chad,

First of all, it's urlencode() - not encodeURI(). I have no idea what
that function does - it's not part of the PHP standard library.

And you're using AJAX - which is something completely different. Not
being an AJAX user myself, I can't say what your problem is. All I know
is I use urlencode() with some regularity and it works fine. I've also
tried strings with a '#' in them and it's OK.

The '#' is used in an href to indicate a tag (<a name=...>) on a page.
Perhaps AJAX is getting confused. I wouldn't know. Or maybe your
encodeURI() function isn't doing the same thing.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Mar 20 '07 #4

P: n/a
ch***********@gmail.com wrote:
On Mar 19, 8:45 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>chad.a.mor...@gmail.com wrote:
I don't have a lot of experience using $_GET.
I need to know how to pass characters in using the $_GET method. The
character I'm having a problem with right now is '#', but I'm sure
there are others.
Could anyone give me a list of characters that need to be escaped
using $_GET, and then also how to use them?
Also, could you tell me if any characters simply are not allowed in a
get?
Example:
getData.php?type=edit&user=myName&item=Item#1
Thanks,
Chad

urlencode() your parameters.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -

- Show quoted text -

I'm trying to go from javascript (making the call) to php.

For example:

function getData()
{
var user = "user1" ;
var item = encodeURI( "Item #1" ) ;
xmlHttp.open( 'GET' , 'addData.php?user=' + user + '&item=' +
item ) ;
}
However, the encodeURI() function on the string give returns the
following:

Item%20#1

So, it is leaving the pound sign, which is messing me up.

Any other thoughts? Perhaps I'm not using the functions correctly?
Indeed.

encodeURI leaves ; / ? : @ & = + $ , # all intact.

What you need in Javascript is escape(), not encodeURI().

Tip: Buy a good JS book and you never fall for this kind of thing again.
I recommend Javascript, the definitive guide, by Flanagan (O Reilly)

Regards,
Erwin Moller
>
Chad
Mar 20 '07 #5

P: n/a
On Mar 20, 11:20 am, Erwin Moller
<since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
chad.a.mor...@gmail.com wrote:
On Mar 19, 8:45 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
chad.a.mor...@gmail.com wrote:
I don't have a lot of experience using $_GET.
I need to know how to pass characters in using the $_GET method. The
character I'm having a problem with right now is '#', but I'm sure
there are others.
Could anyone give me a list of characters that need to be escaped
using $_GET, and then also how to use them?
Also, could you tell me if any characters simply are not allowed in a
get?
Example:
getData.php?type=edit&user=myName&item=Item#1
Thanks,
Chad
urlencode() your parameters.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -
- Show quoted text -
I'm trying to go from javascript (making the call) to php.
For example:
function getData()
{
var user = "user1" ;
var item = encodeURI( "Item #1" ) ;
xmlHttp.open( 'GET' , 'addData.php?user=' + user + '&item=' +
item ) ;
}
However, the encodeURI() function on the string give returns the
following:
Item%20#1
So, it is leaving the pound sign, which is messing me up.
Any other thoughts? Perhaps I'm not using the functions correctly?

Indeed.

encodeURI leaves ; / ? : @ & = + $ , # all intact.

What you need in Javascript is escape(), not encodeURI().

Tip: Buy a good JS book and you never fall for this kind of thing again.
I recommend Javascript, the definitive guide, by Flanagan (O Reilly)

Regards,
Erwin Moller


Chad- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -
Thanks for the help Erwin and Jerry. I will definitely check out the
book you mentioned. I'm finding that the more in depth that I go, the
better off I'd be with a book.

THANKS!!

Mar 22 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.