sixseven Posted August 19, 2010 Share Posted August 19, 2010 Hello, I'm pretty new to php and have a small problem I can't figure out. I have passed some copy (john & mary) from a small form to a url with php (i used urlencode). The code in the url looks like this john+%26+mary. My problem is, how do I display the %26 as an actual ampersand (&) on the html page? Here is the snippet of code that I am currently using to display the names. <?php echo htmlentities($_GET['gallery']); ?> I have searched and searched and can't find anything to figure this out. Any help would be great. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/211194-display-ampersand-hex-code-from-url-in-html/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 19, 2010 Share Posted August 19, 2010 urldecode would convert it back to a literal &. Then htmlentities() would convert it to an entity that could be displayed instead of processed in html. Quote Link to comment https://forums.phpfreaks.com/topic/211194-display-ampersand-hex-code-from-url-in-html/#findComment-1101296 Share on other sites More sharing options...
hcdarkmage Posted August 19, 2010 Share Posted August 19, 2010 Dang it . . . beaten to it. PFMaBiSmAd is right. Quote Link to comment https://forums.phpfreaks.com/topic/211194-display-ampersand-hex-code-from-url-in-html/#findComment-1101299 Share on other sites More sharing options...
sixseven Posted August 19, 2010 Author Share Posted August 19, 2010 THanks for the reply. Would I write the code like this: <?php echo urldecode(htmlentities($_GET['gallery'])); ?> I tried it and it didn't work. Quote Link to comment https://forums.phpfreaks.com/topic/211194-display-ampersand-hex-code-from-url-in-html/#findComment-1101325 Share on other sites More sharing options...
hcdarkmage Posted August 19, 2010 Share Posted August 19, 2010 $gallery = urldecode($_GET['gallery']); echo htmlentities($gallery); Quote Link to comment https://forums.phpfreaks.com/topic/211194-display-ampersand-hex-code-from-url-in-html/#findComment-1101328 Share on other sites More sharing options...
sixseven Posted August 19, 2010 Author Share Posted August 19, 2010 Strange. I tried that and it still doesn't display the ampersand and anything after the ampersand. Looking at your code it seems to make sense, but it still doesn't work. Any ideas as to why this might be happening? Quote Link to comment https://forums.phpfreaks.com/topic/211194-display-ampersand-hex-code-from-url-in-html/#findComment-1101353 Share on other sites More sharing options...
btherl Posted August 20, 2010 Share Posted August 20, 2010 Usually you don't need to urldecode a $_GET value. Try viewing the source of the page and see what you are getting. You should see "&" in the source. If you don't, post what you see here as well as the code that generates it, and we can probably tell you where the encoding is going wrong. Also it would be good if you print out the original value from $_GET as well. Quote Link to comment https://forums.phpfreaks.com/topic/211194-display-ampersand-hex-code-from-url-in-html/#findComment-1101463 Share on other sites More sharing options...
sixseven Posted August 20, 2010 Author Share Posted August 20, 2010 It looks like with a little messing around from what all of you posted, I fixed the problem. There was another spot that I missed that was passing url info. I took off the urldecode on the GET value and urlencoded another and I'm set. I now have a much better understanding of encode and decode. Thanks for all of the help. Quote Link to comment https://forums.phpfreaks.com/topic/211194-display-ampersand-hex-code-from-url-in-html/#findComment-1101649 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.