- substr: documentation ( source)
- ord: documentation ( source)
- sprintf: documentation ( source)
<?php
$str = "天在变
我心
融化
谁能懂
恨
与谁共";
function asc2bin($temp) {
$len = strlen($temp);
for($i=0; $i<$len; $i++) {
$data .= sprintf("%08b", ord(substr($temp, $i, 1)));
}
return $data;
}
echo asc2bin($str);