php urlencode encodes wrong?

Go To StackoverFlow.com

1

If I try to encode the url

http://herthabsc.de/index.php?id=3631&tx_ttnews[tt_news]=13144&cHash=9ef2e9ee006fb16188ebf764232a0ba9 

with urlencode() or http_build_query() it gives me the result

http%3A%2F%2Fherthabsc.de%2Findex.php%3Fid%3D3631%26%23038%3Btx_ttnews%5Btt_news%5D%3D13144%26%23038%3BcHash%3D9ef2e9ee006fb16188ebf764232a0ba9

But that's not what it should be. Is there a known bug? Or problems in use with wordpress?

2012-04-03 19:52
by Jonathan
What do you expect it to be? That's an encoded URL. Do you only wish to encode the querystring part of that URL - Michael Berkowski 2012-04-03 19:55
the function works as described in the manual, it's your expectations that are wrong - NoName 2012-04-03 20:06
it actually has to be http%3A//herthabsc.de/index.php%3Fid%3D3631%26txttnews%5Bttnews%5D%3D13144%26cHash%3D9ef2e9ee006fb16188ebf764232a0ba - Jonathan 2012-04-03 20:07
And why is that so? The manual says: "Returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits" - therefore replacing the slashes with %2F is the expected behavior - Niko 2012-04-03 20:17
No I mean the & symbol should be %26 and its %26%23038%3 - Jonathan 2012-04-03 20:28
Comes out as http%3A%2F%2Fherthabsc.de%2Findex.php%3Fid%3D3631%26tx_ttnews%5Btt_news%5D%3D13144%26cHash%3D9ef2e9ee006fb16188ebf764232a0ba9 when I run it through urlencode(). Show us your actual code - ceejayoz 2012-04-03 20:39


4

You've double encoded the URL. Running urldecode() on your output string is giving me the following: http://herthabsc.de/index.php?id=3631&tx_ttnews[tt_news]=13144&cHash=9ef2e9ee006fb16188ebf764232a0ba9

EDIT: try the following

urlencode(html_entity_decode('http://herthabsc.de/index.php?id=3631&tx_ttnews[tt_news]=13144&cHash=9ef2e9ee006fb16188ebf764232a0ba9'));
2012-04-03 20:37
by Crashspeeder
yes, probably the poster is viewing the link in a browser, where it shows &#038 as a single ampersand characte - kuba 2012-04-03 20:39
yes this is given to me too - Jonathan 2012-04-03 21:26
but i encode it only once - Jonathan 2012-04-03 21:35
I'm doing this in Google Chrom - Jonathan 2012-04-05 11:39
I get the url from the content of a wordpress shortcod - Jonathan 2012-04-05 12:32
@user1248410 See my edit for how to fix this - Crashspeeder 2012-04-05 13:41
thanks that the solution - Jonathan 2012-04-05 21:21
Ads