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 - 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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.