3v4l.org

run code in 300+ PHP versions simultaneously
<?php $mystring = "aHR0cHM6Ly93d3cucGhwLm5ldC9tYW51YWwvZW4vZnVuY3Rpb24uc3RyLXNwbGl0LnBocA=="; $totalSegments = 4; $segments = []; while ($totalSegments) { --$totalSegments; $segmentLength = rand(1, strlen($mystring) - $totalSegments); [$segments[], $mystring] = sscanf($mystring, "%{$segmentLength}s%s"); } var_export($segments);

preferences:
29.17 ms | 406 KiB | 5 Q