3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $str = "this is a long string"; $length = strlen($str); $dir = -1; $delta = $length; $maxlength = 12; while(intval($delta)){ $delta = $delta / 2; $length = $length + $dir * $delta; if($dir * (strlen(substr($str, 0, $length)) - $maxlength) > 0) $dir = -$dir; echo substr($str, 0, $length)." ". $delta. "\n"; } ?>
based on 4Cevt
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.3.1
this is a 10.5 this is a long 5.25 this is a lon 2.625 this is a l 1.3125 this is a lo 0.65625