php urlencode encodes wrong?

Go To


If I try to encode the url[tt_news]=13144&cHash=9ef2e9ee006fb16188ebf764232a0ba9 

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

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// - 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 when I run it through urlencode(). Show us your actual code - ceejayoz 2012-04-03 20:39


You've double encoded the URL. Running urldecode() on your output string is giving me the following:[tt_news]=13144&cHash=9ef2e9ee006fb16188ebf764232a0ba9

EDIT: try the following

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