3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = chr(255); var_dump( $str, strtobits($str), mb_check_encoding($str, '7bit'), is_7bit_clean($str) ); function is_7bit_clean(string $str):bool{ for($i=0,$imax=strlen($str);$i<$imax;++$i){ if(ord($str[$i]) & (1 << 7)){ return false; } } return true; } function strtobits(string $str): string { $ret = ""; for ($i = 0; $i < strlen($str); ++ $i) { $ord = ord($str[$i]); for ($bitnum = 7; $bitnum >= 0; -- $bitnum) { if ($ord & (1 << $bitnum)) { $ret .= "1"; } else { $ret .= "0"; } } } return $ret; }
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.4 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
string(1) "�" string(8) "11111111" bool(false) bool(false)
Output for 8.1.2 - 8.1.3
string(1) "�" string(8) "11111111" bool(true) bool(false)
Output for 8.1.0 - 8.1.1

Process exited with code 139.

preferences:
124.33 ms | 408 KiB | 5 Q