开发者

Convert file to binary string with PHP

开发者 https://www.devze.com 2023-02-17 03:33 出处:网络
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

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

精彩评论

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