Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UTF-16 PHP String to UTF-8

I have a string on a variable $str after successfully decrypting AES cipher with mcrypt_decrypt. If I try to print str to screen, I do notice that it has a blank space between each letter, that actually is a NULL termination (\x00) given by UTF-16 character encoding.

Array ( [1] => 33 [2] => 0 [3] => 34 [4] => 0 [5] => 35 [6] => 0 ... )

I've tried many ways to turn it into UTF-8 but I failed. What can I do?

like image 632
user1365914 Avatar asked May 20 '26 00:05

user1365914


1 Answers

You should use mb-convert-encoding function

$str = mb_convert_encoding($str, "UTF-8" , "UTF-16LE");
like image 140
Matias Elorriaga Avatar answered May 22 '26 14:05

Matias Elorriaga



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!