base64_encode is returning a different string to the linux
Why is this?
$ php <?php echo base64_encode('test'); ?> dGVzdA==
$ echo 'test' | base64 dGVzdAo=
echo usually outputs a new line character at the end of the string, to suppress that use the
$ echo -n 'test' | base64 dGVzdA==
Similarly for PHP:
$ php <?php echo base64_encode("test\n"); ?> dGVzdAo=
open console in your browser, type
You have extra character in your input. And that is
When doing an echo it gives me this:
MacPro:~ bardiir$ echo 'test' test MacPro:~ bardiir$
I’d guess you might have an included line-ending in the unix one as echo is probably appending a newline character even if you pipe it throuch to the base64 encode.
base64 has a new line at the end.
It is because Unix version encodes also the end of line.
To receive similar effect in PHP you will have to do something like that:
which will output:
See the proof here: ideone.com/HorVD
EDIT: As Charles mentioned,
PHP_EOL is platform-specific, so to check the above on Windows you will have to replace it with Unix-like end of line symbol:
The same to above guys.
In mac os X, just test this :
$ echo 'test' | cat -e test$
$ echo -n 'test' | cat -e test
And,about the echo command, can see the tip: