Reputation: 11448
I have:
$str = 'test%2B';
echo html_entity_decode($str);
I want it to return test +
What am I doing wrong?
NOTE: Sorry, the string cannot be modified. It's from an external source, I just need to make it replace the %2B with + signs somehow with PHP.
Upvotes: 1
Views: 458
Reputation: 10499
You didn't escape the space, and you should be using urldecode
instead of html_entity_decode
.
Try
$str = 'test%20%2B';
echo urldecode($str); // test +
If you wish to use html_entity_decode
, use +
:
$str = 'test +';
echo html_entity_decode($str); // test +
EDIT: If you need to decode a url that you cannot change yourself, urldecode
should still work fine.
Upvotes: 6
Reputation: 237985
That string is encoded for a URL, not with HTML entities.
You need urldecode
.
echo urldecode($str); // "test +"
An HTML-encoded string would look like this: test +
, because none of those characters need HTML-encoding.
Upvotes: 2
Reputation: 14619
Try +
instead. In your example, you are using URL encoding syntax and not HTML entity syntax.
Upvotes: 0