开发者

Convert file to binary string with PHP

I'm looking to convert a file to a binary string, preferably using PHP. Is this possible?

MORE INFO: I'd like to have users upload a 开发者_运维百科small file through a form, and return the binary representation of that file as a binary string - i.e ones and zeros.


$str = 'hello world';
$length = strlen($str);
$result = '';

for ($i = 0; $i < $length; $i++) {
    $result .= str_pad(decbin(ord($str[$i])), 8, '0', STR_PAD_LEFT);
}

echo $result;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜