Gaurav Gupta
Gaurav Gupta

Reputation: 1698

URL Decoding in PHP not working as supposed to be

I am trying to decode this URL string using PHP's urldecode function:

urldecode("%3CR201810579707%3E%20%3C20180828%3E%20%3C20180912%3E%20%3C1033.00%3E%20%3CY%3E%20%3C0.00%21NA%3E");

This is supposed to output...

<R201810579707> <20180828> <20180912> <1033.00> <Y> <0.00!NA>

...but instead is ouptutting this

<20180828> <20180912> <1033.00> <0.00!NA>

I've tested the string in a php online decoder with great success, but can't seem to do this operation server side. Any ideas?

Upvotes: 0

Views: 285

Answers (1)

Barmar
Barmar

Reputation: 780655

If you're printing the result on a web page, the angle brackets will be treated as tag delimiters. You can display it literally by calling htmlentities():

echo htmlentities(urldecode("%3CR201810579707%3E%20%3C20180828%3E%20%3C20180912%3E%20%3C1033.00%3E%20%3CY%3E%20%3C0.00%21NA%3E"));

Upvotes: 3

Related Questions