Skip to main content
Inspiring
November 1, 2007
Answered

PHP, handling # in a string pass in the querystring

  • November 1, 2007
  • 4 replies
  • 532 views
I am new to PHP from the ASP world. I am working on a shopping cart where, I am passing item name via the querystring to the processcart.php file. It works great until I place a # sign in the item name. Is there a right way to handle strings with # signs in the middle of them.

David
This topic has been closed for replies.
Correct answer Newsgroup_User
DEPearson wrote:
> I am new to PHP from the ASP world. I am working on a shopping cart where, I
> am passing item name via the querystring to the processcart.php file. It works
> great until I place a # sign in the item name. Is there a right way to handle
> strings with # signs in the middle of them.

PHP can handle # in a string without problems. The mistake that you're
making is to pass # through a query string. In a URL, # indicates a
named element inside the page. To use # as a character that is preserved
as a literal value, you need to urlencode it. You can either do that
with the urlencode() function. It's probably simpler to use the
urlencoding directly: %23 represents #.

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/

4 replies

Inspiring
November 2, 2007
DEPearson wrote:
> PS: you book PHP solutions help to learn about the Header already sent error,
> thanks again.

Glad the book has been of help.

> Not sure if like php yet, just started a side job with php.

It depends what you're used to. I started dynamic development with ASP,
and hated it. A variety of circumstances forced me into switching to
PHP. I took to it like a duck to water.

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
DEPearsonAuthor
Inspiring
November 2, 2007
David,
Thanks for the quick reply. I have consider the urlencode function. The detail page for the product is built using xsl, so I am not sure if I call a php function after the transformation process.

I think your right about doing urlencoding directly. I will try doing a string replacement function in XSL to change the value to %23.

David Pearson

PS: you book PHP solutions help to learn about the Header already sent error, thanks again.

Not sure if like php yet, just started a side job with php.
Newsgroup_UserCorrect answer
Inspiring
November 1, 2007
DEPearson wrote:
> I am new to PHP from the ASP world. I am working on a shopping cart where, I
> am passing item name via the querystring to the processcart.php file. It works
> great until I place a # sign in the item name. Is there a right way to handle
> strings with # signs in the middle of them.

PHP can handle # in a string without problems. The mistake that you're
making is to pass # through a query string. In a URL, # indicates a
named element inside the page. To use # as a character that is preserved
as a literal value, you need to urlencode it. You can either do that
with the urlencode() function. It's probably simpler to use the
urlencoding directly: %23 represents #.

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
DEPearsonAuthor
Inspiring
November 1, 2007
Sorry about the double post, having internet connection problems here.