3

I'm working on it

$source = mb_convert_encoding('test', "unicode", "utf-8");
$source = unpack('C*', $source);
var_dump($source);

return:

array (size=8)
  1 => int 0
  2 => int 116
  3 => int 0
  4 => int 101
  5 => int 0
  6 => int 115
  7 => int 0
  8 => int 116

but i want this return:

array (size=8)
  1 => int 116
  2 => int 0
  3 => int 101
  4 => int 0
  5 => int 115
  6 => int 0
  7 => int 116
  8 => int 0

I want use this return in openssl function for encryption. just $source important to me, i write other code for debugging.

What can i do to solve this problem?

0

1 Answer 1

11

"Unicode" is not a real encoding; it's the name of the overarching standard and used as an alias for UTF-16BE mostly by Microsoft, and apparently PHP supports it for that reason. What you expect is UTF-16LE, so use that explicitly:

$source = mb_convert_encoding('test', 'UTF-16LE', 'UTF-8');
Sign up to request clarification or add additional context in comments.

Comments

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.