3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CookieCodec { /** * All characters valid in a cookie according to https://tools.ietf.org/html/rfc6265 and we have additionally * removed % (used for escape sequences) and + (which, if not encoded, is interpreted as space in cookies by PHP, * but there's no equivalent built-in JS decoding function, so we escape it to make decoding equivalent in both * cases). */ private const COOKIE_CHARSET = '!#$&\'()*-./0123456789:<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~'; public static function encode($string) { $string = (string) $string; $output = ''; for ($i = 0, $m = \strlen($string); $i < $m; $i++) { $char = $string[$i]; if (\strpos(self::COOKIE_CHARSET, $char) === false) { $ord = \ord($char); $code = \strtoupper(\dechex($ord)); $output .= $ord > 15 ? "%$code" : "%0$code"; } else { $output .= $char; } } return $output; } }
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33
Parse error: syntax error, unexpected 'const' (T_CONST), expecting variable (T_VARIABLE) in /in/gQKLF on line 10
Process exited with code 255.

preferences:
232.9 ms | 402 KiB | 291 Q