3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $segments = [1,2,3,4,5,6,7,8,9,1]; $box_size = 4; $input = 'Loremipsumdolorsitametconsecteturadipiscingeli'; $output = []; function string_to_stream($string) { $in = fopen('php://memory','r+'); fwrite($in, $string); rewind($in); return $in; } $stream = string_to_stream($input); $left_over = ''; while (($segment = array_shift($segments)) !== null) { while (strlen($left_over) < $segment) { $left_over .= fread($stream, $box_size); } $output[] = substr($left_over, 0, $segment); $left_over = substr($left_over, $segment); } if (implode('', $output) === $input) { echo 'Algorithm Correct !' . PHP_EOL . PHP_EOL; } foreach ($output as $v) { echo $v . PHP_EOL; }
Output for 5.6.0 - 7.3.0alpha1
Algorithm Correct ! L or emi psum dolor sitame tconsec teturadi piscingel i