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;
精彩评论