Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

PHP, handling # in a string pass in the querystring

Explorer ,
Nov 01, 2007 Nov 01, 2007
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
TOPICS
Server side applications
533
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Nov 01, 2007 Nov 01, 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 charact...
Translate
Explorer ,
Nov 01, 2007 Nov 01, 2007
Sorry about the double post, having internet connection problems here.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 01, 2007 Nov 01, 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/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 01, 2007 Nov 01, 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 02, 2007 Nov 02, 2007
LATEST
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/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines