0

in PHP I have this code to convert a string to binary and encode to Base 64:

    <?php
$value = pack('H*', "b4h3h347h38f3g734ff");
echo base64_encode($value);

But how I can do that in Javascript ?

Thank you!

zZPrank
  • 1
  • 3

1 Answers1

0

See text_to_binary here in SO.

Use btoa() and atob() to convert to and from base64 encoding.

Community
  • 1
  • 1
tale852150
  • 1,618
  • 3
  • 17
  • 23
  • I tried that method but when I compare the result of PHP and Javascript, it is totally different – zZPrank May 21 '17 at 03:45
  • You have a similar way in javascript with the turbocommons library, easy and extensively tested: https://turboframework.org/en/app/stringutils/base64-encode – Jaume Mussons Abad Oct 30 '22 at 09:02