2019-07-18 06:53:55 +00:00
|
|
|
<?php
|
|
|
|
|
2021-09-15 11:27:22 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
require_once '../vendor/autoload.php';
|
2019-12-11 12:35:54 +00:00
|
|
|
|
2019-07-18 06:53:55 +00:00
|
|
|
// action => label
|
|
|
|
$buttons = [
|
|
|
|
'urlencode' => 'URL Encode',
|
|
|
|
'urldecode' => 'URL Decode',
|
|
|
|
'b64encode' => 'Base64 Encode',
|
|
|
|
'b64decode' => 'Base64 Decode',
|
|
|
|
'htmlencode' => 'HTML Encode',
|
|
|
|
'htmldecode' => 'HTML Decode',
|
2019-07-18 07:20:22 +00:00
|
|
|
'uuencode' => 'UU Encode',
|
|
|
|
'uudecode' => 'UU Decode',
|
2019-07-18 06:53:55 +00:00
|
|
|
'qprintencode' => 'Qprint Encode',
|
|
|
|
'qprintdecode' => 'Qprint Decode',
|
|
|
|
'hash' => 'Hash',
|
|
|
|
'hex' => 'Hex',
|
2021-04-19 11:48:39 +00:00
|
|
|
'prettyjson' => 'Pretty JSON',
|
2019-07-18 06:53:55 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
$str = $result = $_GET['str'] ?? '';
|
|
|
|
$action = $_GET['action'] ?? '';
|
2021-09-15 15:26:10 +00:00
|
|
|
$help = 'https://www.php.net/manual/';
|
2019-07-18 06:53:55 +00:00
|
|
|
|
|
|
|
if ($action == 'reset') {
|
|
|
|
http_response_code(302);
|
|
|
|
header("Location: /");
|
|
|
|
die();
|
|
|
|
|
|
|
|
} elseif ($action == 'urlencode') {
|
2019-12-11 12:35:54 +00:00
|
|
|
$result = rawurlencode($str)?: $str;
|
|
|
|
$help = 'https://www.php.net/rawurlencode';
|
2019-07-18 06:53:55 +00:00
|
|
|
|
|
|
|
} elseif ($action == 'urldecode') {
|
2019-12-11 12:35:54 +00:00
|
|
|
$result = rawurldecode($str)?: $str;
|
|
|
|
$help = 'https://www.php.net/rawurldecode';
|
2019-07-18 06:53:55 +00:00
|
|
|
|
|
|
|
} elseif ($action == 'b64encode') {
|
|
|
|
$result = base64_encode($str)?: $str;
|
2019-12-11 12:35:54 +00:00
|
|
|
$help = 'https://www.php.net/base64_encode';
|
2019-07-18 06:53:55 +00:00
|
|
|
|
|
|
|
} elseif ($action == 'b64decode') {
|
|
|
|
$result = base64_decode($str)?: $str;
|
2019-12-11 12:35:54 +00:00
|
|
|
$help = 'https://www.php.net/base64_decode';
|
2019-07-18 06:53:55 +00:00
|
|
|
|
|
|
|
} elseif ($action == 'htmlencode') {
|
|
|
|
$result = htmlentities($str, ENT_QUOTES | ENT_HTML5)?: $str;
|
2019-12-11 12:35:54 +00:00
|
|
|
$help = 'https://www.php.net/htmlentities';
|
2019-07-18 06:53:55 +00:00
|
|
|
|
|
|
|
} elseif ($action == 'htmldecode') {
|
|
|
|
$result = html_entity_decode($str, ENT_QUOTES | ENT_HTML5)?: $str;
|
2019-12-11 12:35:54 +00:00
|
|
|
$help = 'https://www.php.net/html_entity_decode';
|
2019-07-18 06:53:55 +00:00
|
|
|
|
|
|
|
} elseif ($action == 'uuencode') {
|
|
|
|
$result = convert_uuencode($str)?: $str;
|
2019-12-11 12:35:54 +00:00
|
|
|
$help = 'https://www.php.net/convert_uuencode';
|
2019-07-18 06:53:55 +00:00
|
|
|
|
|
|
|
} elseif ($action == 'uudecode') {
|
|
|
|
$result = convert_uudecode($str)?: $str;
|
2019-12-11 12:35:54 +00:00
|
|
|
$help = 'https://www.php.net/convert_uudecode';
|
2019-07-18 06:53:55 +00:00
|
|
|
|
|
|
|
} 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);
|
|
|
|
}
|
2019-11-05 09:32:39 +00:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2019-07-18 06:53:55 +00:00
|
|
|
$result = trim($result);
|
2019-12-11 12:35:54 +00:00
|
|
|
$help = 'https://www.php.net/hash';
|
2019-07-18 06:53:55 +00:00
|
|
|
|
|
|
|
} elseif ($action == 'hex') {
|
2019-12-11 12:35:54 +00:00
|
|
|
$dumper = new Clue\Hexdump\Hexdump();
|
|
|
|
$result = $dumper->dump($str);
|
|
|
|
$help = 'https://github.com/clue/php-hexdump';
|
2019-07-18 06:53:55 +00:00
|
|
|
|
|
|
|
} elseif ($action == 'qprintencode') {
|
|
|
|
$result = quoted_printable_encode($str)?: $str;
|
2019-12-11 12:35:54 +00:00
|
|
|
$help = 'https://www.php.net/quoted_printable_encode';
|
2019-07-18 06:53:55 +00:00
|
|
|
|
|
|
|
} elseif ($action == 'qprintdecode') {
|
|
|
|
$result = quoted_printable_decode($str)?: $str;
|
2019-12-11 12:35:54 +00:00
|
|
|
$help = 'https://www.php.net/quoted_printable_decode';
|
2021-04-19 11:48:39 +00:00
|
|
|
|
|
|
|
} elseif ($action == 'prettyjson') {
|
|
|
|
$jd = json_decode($str);
|
|
|
|
if (JSON_ERROR_NONE !== json_last_error()) {
|
|
|
|
$result = 'Error: '. json_last_error_msg() ."\n\n". $str;
|
|
|
|
} else {
|
2021-09-15 11:27:22 +00:00
|
|
|
$result = json_encode($jd, JSON_PRETTY_PRINT | JSON_PRESERVE_ZERO_FRACTION | JSON_UNESCAPED_SLASHES);
|
2021-04-19 11:48:39 +00:00
|
|
|
}
|
|
|
|
$help = 'https://www.php.net/json';
|
|
|
|
|
2019-07-18 06:53:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
?><!doctype html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-70198-12"></script>
|
|
|
|
<script>
|
|
|
|
window.dataLayer = window.dataLayer || [];
|
|
|
|
function gtag() { dataLayer.push(arguments) }
|
|
|
|
gtag('js', new Date());
|
|
|
|
gtag('config', 'UA-70198-12');
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<meta charset="utf-8">
|
2021-09-15 15:26:10 +00:00
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
2019-07-18 06:53:55 +00:00
|
|
|
|
2021-09-15 15:26:10 +00:00
|
|
|
<title>Decode/Encode everything</title>
|
2021-09-15 11:27:22 +00:00
|
|
|
<meta name="author" content="Sergio Álvarez <correo@sergio.am>">
|
2021-09-15 15:26:10 +00:00
|
|
|
<meta name="description" content="Encode and Decode strings from/to URL, Base64, HTML entities, UU, Qprint, hash, hex and more." />
|
2021-09-15 11:27:22 +00:00
|
|
|
|
|
|
|
<link rel="apple-touch-icon" sizes="180x180" href="/img/favicon.io/apple-touch-icon.png">
|
|
|
|
<link rel="icon" type="image/png" sizes="32x32" href="/img/favicon.io/favicon-32x32.png">
|
|
|
|
<link rel="icon" type="image/png" sizes="16x16" href="/img/favicon.io/favicon-16x16.png">
|
|
|
|
<link rel="manifest" href="/img/favicon.io/site.webmanifest">
|
2019-07-18 06:53:55 +00:00
|
|
|
|
2021-09-15 15:26:10 +00:00
|
|
|
<link rel="stylesheet" href="https://unpkg.com/@picocss/pico@latest/css/pico.min.css">
|
|
|
|
<link rel="stylesheet" href="/css/custom.css">
|
2019-07-18 06:53:55 +00:00
|
|
|
</head>
|
|
|
|
|
2021-09-15 15:26:10 +00:00
|
|
|
<body class="container-fluid">
|
2019-07-18 06:53:55 +00:00
|
|
|
<form method="get">
|
2021-09-15 15:26:10 +00:00
|
|
|
<header class="grid">
|
2019-07-18 06:53:55 +00:00
|
|
|
<?php foreach ($buttons as $act => $label) { ?>
|
2021-09-15 15:26:10 +00:00
|
|
|
<button type="submit" name="action" value="<?=$act?>" class="<?=($action == $act? ' contrast': '')?>"><?=$label?></button>
|
2019-07-18 06:53:55 +00:00
|
|
|
<?php } ?>
|
2021-09-15 15:26:10 +00:00
|
|
|
<a href="/">Reset</a>
|
|
|
|
<a href="<?=$help?>">Help</a>
|
|
|
|
</header>
|
2019-07-18 06:53:55 +00:00
|
|
|
|
2021-09-15 15:26:10 +00:00
|
|
|
<main class="grid">
|
|
|
|
<textarea name="str" class="form-input" placeholder="Paste a string here"><?=htmlentities($result, ENT_QUOTES | ENT_HTML5 | ENT_IGNORE)?></textarea>
|
|
|
|
</main>
|
2019-07-18 06:53:55 +00:00
|
|
|
|
2021-09-15 15:26:10 +00:00
|
|
|
<footer class="grid">
|
|
|
|
<small>Contact me via <a href="mailto:correo@sergio.am">email</a> or <a href="https://twitter.com/xergio">twitter</a>. Made with pure <a href="https://php.net/">PHP</a> and <a href="https://picocss.com/"><strong>Pico</strong>.css</a>. <a href="https://sergio.am/code/dencode.xrg.es">Code</a>.</small>
|
|
|
|
</footer>
|
|
|
|
</form>
|
2019-07-18 06:53:55 +00:00
|
|
|
</body>
|
|
|
|
</html>
|