简体   繁体   中英

How to decode base64 (in little endian) with PHP?

How can I decode a base64 encoded message in PHP? I know how to use PHP_base64_decode function, but I wanna know how to write little endian part, like the code below, it is base64 code with little endian: (how to write little endian part in php)

Original Base64 Content ( as posted by original poster ) :

https://stackoverflow.com/revisions/viewmarkup/374860

使用base64_decode()函数。

Base64 converts a stream of bytes into printable characters. There is nothing that could go wrong.

'Little-endian' describes one of two ways a number can be converted into a sequence of bytes: little-endian = least significant byte first. Big-endian = most significant byte first. UTF-8 is a string encoding into a stream of bytes, and there is concept of endianness to be applied. UTF16, however, encodes text into 16-bit words, and there are two ways to encode the words into bytes, and UTF16 comes in two flavors: UTF16LE (little endian) and UTF16BE (big endian). The same concept of endianness is also applied to UTF32, but this is not a common format.

If, by little-endian, you mean UTF16LE, then you have to decide to which format you want to re-encode the string (probably UTF-8).
You can use this function: mb_convert_encoding($input, 'UTF-8', 'UTF-16LE') [1][2]

If, by little-endian, you mean numbers, then you have to specify the endianness at whichever point you are converting the bytes into numbers.

[1] http://cz.php.net/manual/en/function.mb-convert-encoding.php
[2] http://cz.php.net/manual/en/mbstring.supported-encodings.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM