3

I need to remove white spaces from a base64 encoded file . When Base64 gets POSTed, and I got more white spaces in out put string.Where did these white spaces are coming

How do I remove these whitespcaes

Duke
  • 35,420
  • 13
  • 53
  • 70
  • what code are you using to generate and post the base64 encoded string? POSTing a string shouldn't add more whitespace – Timothy Groote Jan 27 '12 at 11:02
  • Its a image binary string(converted an image to binary and encoded with base64) and posted from iPhone program – Duke Jan 27 '12 at 11:12

2 Answers2

4

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

benji
  • 681
  • 9
  • 23
2

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

Timothy Groote
  • 8,614
  • 26
  • 52
  • .This is ok when we are communicating php to php ,I think this is a weird state , first time I've been working with PHP and iPhone app ,any way Ben's answer solved my problem ,Sure I will study more about your answer – Duke Jan 27 '12 at 11:56
  • url encoding and decoding, as html encoding and decoding should not differ per platform, since they adhere to the same standards. I have done the same with a MonoTouch iPhone application. – Timothy Groote Jan 27 '12 at 12:36