3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Base64Url { /** * @param $str string * * @return string */ public static function encode($str) { $std = @base64_encode($str); if ($std === false) { throw new \Exception('base64_encode() failed'); } return rtrim(strtr($std, '+/', '-_'), '='); } /** * @param $str string * * @return string */ public static function decode($str) { $result = ''; if ($str !== null) { if (!is_string($str)) { throw new \Exception('Only strings can be decoded'); } $std = strtr($str, '-_', '+/').str_repeat('=', strlen($str) % 4); $result = base64_decode($std, true); if ($result === false) { throw new \Exception('base64_decode() failed'); } } return $result; } } $ph = '{"typ":"JWT",' . "\n ". '"alg":"HS256"}'; echo Base64Url::decode(Base64Url::encode($ph));
based on WAoU0
Output for 7.1.0 - 7.2.0
Fatal error: Uncaught Exception: base64_decode() failed in /in/pBKf2:36 Stack trace: #0 /in/pBKf2(45): Base64Url::decode('eyJ0eXAiOiJKV1Q...') #1 {main} thrown in /in/pBKf2 on line 36
Process exited with code 255.
Output for 5.3.20 - 7.0.20
{"typ":"JWT", "alg":"HS256"}