问题
I was wondering how one would get the Text representation of a series of bytes in PHP? (Basically, the PHP version of C#'s Encoding.getString(string s)
method.)
I've been scouring google, and I can find how to get a textstring-to-bytes, but not the other way around.
回答1:
In PHP such a method:
Encoding.GetString Method (Byte[])
is not necessary because in PHP, strings are like Byte[]. And that's it. So there is no such method, however you can easily write it yourself:
function Encoding_GetString($stringOfBytes) {
return (string) $byteString;
}
If you want to convert an array of integers in the range of 0-255 into a string, you can use chr, array_map and implode:
$string = implode(array_map('chr', $arrayOfByteIntegers));
来源:https://stackoverflow.com/questions/14148054/php-get-string-text-from-bytes