3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * generate command to echo (binary?) data to stdout * * @param string $binary * the (optionally binary) data to echo * @param int $max_ish_line_length * the circa-max line length for the data (PS! it's not always accurate, sometimes it wraps at *circa* this length) * @return string */ function generateBinaryEcho(string $binary, int $max_ish_line_length = 50): string { $inner_max_ish_line_length = (- strlen("'\\")) + $max_ish_line_length; $ret = ""; // http://www.asciitable.com/ $specialAsciiWhitelist = " !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"; $line_length = strlen("echo -ne '"); $translations = [ "\\" => "\\\\", '\'' => '\'\\\'\'', "\n" => "\\n", "\r" => "\\r", ]; for ($i = 0, $imax = strlen($binary); $i < $imax; ++ $i) { if ($line_length >= $inner_max_ish_line_length) { $ret .= "'\\\n'"; $line_length = strlen("'"); } $translation = $binary[$i]; if (isset($translations[$translation])) { $translation = $translations[$translation]; } elseif (ctype_alnum($translation) || ($i !== 0 && strpos($specialAsciiWhitelist, $translation) !== false)) { // no action needed } else { // some binary-ish or unicode-ish data, hex-escape it.. $translation = bin2hex($translation); $translation = str_split($translation, 2); $translation = '\\x' . implode('\\x', $translation); } $line_length += strlen($translation); $ret .= $translation; } $ret = "echo -ne '" . $ret . "'"; return $ret; } $file=<<<'FILE' FROM ubuntu:20.04 ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update -y \ && apt-get install -y php-cli wget git RUN wget 'https://getcomposer.org/installer' -O 'composer-setup.php' RUN php composer-setup.php RUN php -r "unlink('composer-setup.php');" RUN ./composer.phar require php81_bc/strftime FILE; $file = trim($file); echo generateBinaryEcho($file);
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
echo -ne 'FROM ubuntu:20.04\nENV DEBIAN_FRONTEND'\ '=noninteractive \nRUN apt-get update -y \\\n '\ ' && apt-get install -y php-cli wget git\nRUN wg'\ 'et '\''https://getcomposer.org/installer'\'' -O'\ ' '\''composer-setup.php'\''\nRUN php composer-s'\ 'etup.php\nRUN php -r "unlink('\''composer-setup'\ '.php'\'');"\nRUN ./composer.phar require php81_'\ 'bc/strftime'

preferences:
115.74 ms | 403 KiB | 123 Q