[英]Convert file to binary string with PHP
I'm looking to convert a file to a binary string, preferably using PHP. 我希望将文件转换为二进制字符串,最好使用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 - ie 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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.