1

This is my array of bytes: var $x = [108,181,183,176,140,239,53,105,104,47,47,21,147,67,96,87,175,35,67,97]

It has a binary PHP equivalent of gibberish: $x = "lµ·°Œï5ih//“C``W¯#Ca";

Now, what I can use so that javascript:btoa(SOME_ENCODING_FUNCTION($x)); perfectly matches <?php base64_encode($x); ?>?

Thank you!

2
  • Create a string using String.fromCharCode(), then pass it to one of the 100s of JS base64 implementations you can easily find on google. Commented Apr 27, 2012 at 12:52
  • Yes, String.fromCharCode() is what I was looking for. Thanks. Commented Apr 27, 2012 at 14:16

2 Answers 2

4
String.fromCharCode.apply(null, $x);

will return the string to use in btoa.

Sign up to request clarification or add additional context in comments.

Comments

1

You can use base64_encode function but the javascript version of it

http://phpjs.org/functions/base64_encode:358

PHP JS is a good project that aims to port PHP functions to javascript, so if you ever need a javascript function that does exactly the same as a PHP function googling "phpjs _function_name_" will often give you what you are after :)

1 Comment

Apart from not answering my question, if you test it, it won't work on binary strings. Using btoa because it works on bin strings and my project doesn't need cross-browser.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.