Reputation: 2200
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.
Upvotes: 0
Views: 3614
Reputation: 254916
$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;
Upvotes: 4