Reputation: 37060
I need to remove white spaces from a base64 encoded file. When Base64 gets POSTed, and I get more white spaces in the output string. Where did these white spaces coming
How do I remove these whitespaces?
Upvotes: 4
Views: 7359
Reputation: 8652
If you post a string, depending on how you encoded the POST message, the content of the POST message will be encoded (this might be URLencoded, which is the default in most cases) or HTML encoded.
If your POST message contains a +
character where there should have been a space, this means it is being URL-Encoded.
If your POST message contains %20
where there should have been a space, this means it is being HTML-encoded.
PHP offers methods to revert these encoded strings back to the ones they should have been.
urldecode
(PHP4 and PHP5) documentation can be found here
html_entity_decode
(PHP 4.3.0+ and PHP5) documentation can be found here
Upvotes: 2
Reputation: 681
When Base64 gets POSTed, all pluses(+) are parsed as spaces. So I used str_replace to convert the spaces back to pluses. This saved my time
Upvotes: 4