label $buttons = [ 'urlencode' => 'URL Encode', 'urldecode' => 'URL Decode', 'b64encode' => 'Base64 Encode', 'b64decode' => 'Base64 Decode', 'htmlencode' => 'HTML Encode', 'htmldecode' => 'HTML Decode', 'uuencode' => 'UU Encode', 'uudecode' => 'UU Decode', 'qprintencode' => 'Qprint Encode', 'qprintdecode' => 'Qprint Decode', 'hash' => 'Hash', 'hex' => 'Hex', 'prettyjson' => 'Pretty JSON', ]; $str = $result = $_GET['str'] ?? ''; $action = $_GET['action'] ?? ''; $help = 'https://www.php.net/manual/'; if ($action == 'reset') { http_response_code(302); header("Location: /"); die(); } elseif ($action == 'urlencode') { $result = rawurlencode($str)?: $str; $help = 'https://www.php.net/rawurlencode'; } elseif ($action == 'urldecode') { $result = rawurldecode($str)?: $str; $help = 'https://www.php.net/rawurldecode'; } elseif ($action == 'b64encode') { $result = base64_encode($str)?: $str; $help = 'https://www.php.net/base64_encode'; } elseif ($action == 'b64decode') { $result = base64_decode($str)?: $str; $help = 'https://www.php.net/base64_decode'; } elseif ($action == 'htmlencode') { $result = htmlentities($str, ENT_QUOTES | ENT_HTML5)?: $str; $help = 'https://www.php.net/htmlentities'; } elseif ($action == 'htmldecode') { $result = html_entity_decode($str, ENT_QUOTES | ENT_HTML5)?: $str; $help = 'https://www.php.net/html_entity_decode'; } elseif ($action == 'uuencode') { $result = convert_uuencode($str)?: $str; $help = 'https://www.php.net/convert_uuencode'; } elseif ($action == 'uudecode') { $result = convert_uudecode($str)?: $str; $help = 'https://www.php.net/convert_uudecode'; } elseif ($action == 'hash') { $result = "Algorithm Time Len Hash\n"; foreach (hash_algos() as $algo) { $t1 = microtime(true); $r = hash($algo, $str, false); $t2 = (microtime(true) - $t1) * 1000; $result .= sprintf("%-15s %.3f %3d %s\n", $algo, $t2, strlen($r), $r); } // password_hash(PASSWORD_DEFAULT) $t1 = microtime(true); $r = password_hash($str, PASSWORD_DEFAULT); $t2 = (microtime(true) - $t1); $result .= sprintf("%-15s %.3f %3d %s\n", 'password_hash', $t2, strlen($r), $r); $result = trim($result); $help = 'https://www.php.net/hash'; } elseif ($action == 'hex') { $dumper = new Clue\Hexdump\Hexdump(); $result = $dumper->dump($str); $help = 'https://github.com/clue/php-hexdump'; } elseif ($action == 'qprintencode') { $result = quoted_printable_encode($str)?: $str; $help = 'https://www.php.net/quoted_printable_encode'; } elseif ($action == 'qprintdecode') { $result = quoted_printable_decode($str)?: $str; $help = 'https://www.php.net/quoted_printable_decode'; } elseif ($action == 'prettyjson') { $jd = json_decode($str); if (JSON_ERROR_NONE !== json_last_error()) { $result = 'Error: '. json_last_error_msg() ."\n\n". $str; } else { $result = json_encode($jd, JSON_PRETTY_PRINT | JSON_PRESERVE_ZERO_FRACTION | JSON_UNESCAPED_SLASHES); } $help = 'https://www.php.net/json'; } ?>