PHP Get String Text From Bytes [closed]

天涯浪子 提交于 2019-12-14 03:29:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!