I have a URL that I’m passing through a jQuery ajax call (using encodeURIComponent) and decoding in PHP at the other end. I found what I thought to be a problem between rawurldecode() at the PHP end, but when using JUST PHP to rawurlencode() and rawurldecode() a test URL, I managed to get the same problem – can someone point out to me what I need to do here?
To reproduce:
$thing = rawurlencode("www.nzballet.org.nz?pa=thisthing&parmater1=23a¶mter2=another");
echo $thing;
This will produce:
http://www.nzballet.org.nz%3Fpa%3Dthisthing%26parmater1%3D23a%26paramter2%3Danother
If I then:
$rawurl = "www.nzballet.org.nz%3Fpa%3Dthisthing%26parmater1%3D23a%26paramter2%3Danother";
$decoded = rawurldecode($rawurl);
echo $decoded;
I get:
http://www.nzballet.org.nz?pa=thisthing&parmater1=23a¶mter2=another
This is the same output I got when passing between jQuery (ajax) and PHP, so it’s got nothing to do with that part of it. I have charset=UTF-8 specified in the HTML header – can someone enlightne me as to why I’m getting that weird character there?
Thanks!
It looks like your web browser is seeing
¶and assuming you meant¶, which is the entity for a paragraph symbol (¶). See https://meta.stackexchange.com/questions/100905/para-turns-into-within-pre for some more discussion on that issue.To get around it, encode your entities with htmlspecialchars before displaying them:
From the manual: