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?

6
  • 7
    What do you expect it to be? That's an encoded URL. Do you only wish to encode the querystring part of that URL? Commented Apr 3, 2012 at 19:55
  • 1
    the function works as described in the manual, it's your expectations that are wrong. Commented Apr 3, 2012 at 20:06
  • it actually has to be http%3A//herthabsc.de/index.php%3Fid%3D3631%26tx_ttnews%5Btt_news%5D%3D13144%26cHash%3D9ef2e9ee006fb16188ebf764232a0ba9 Commented Apr 3, 2012 at 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. Commented Apr 3, 2012 at 20:17
  • 1
    No I mean the & symbol should be %26 and its %26%23038%3B Commented Apr 3, 2012 at 20:28

1 Answer 1

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'));
Sign up to request clarification or add additional context in comments.

2 Comments

yes, probably the poster is viewing the link in a browser, where it shows &#038 as a single ampersand character
I'm doing this in Google Chrome

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.