index.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. require_once 'vendor/autoload.php';
  3. // action => label
  4. $buttons = [
  5. 'urlencode' => 'URL Encode',
  6. 'urldecode' => 'URL Decode',
  7. 'b64encode' => 'Base64 Encode',
  8. 'b64decode' => 'Base64 Decode',
  9. 'htmlencode' => 'HTML Encode',
  10. 'htmldecode' => 'HTML Decode',
  11. 'uuencode' => 'UU Encode',
  12. 'uudecode' => 'UU Decode',
  13. 'qprintencode' => 'Qprint Encode',
  14. 'qprintdecode' => 'Qprint Decode',
  15. 'hash' => 'Hash',
  16. 'hex' => 'Hex',
  17. ];
  18. $str = $result = $_GET['str'] ?? '';
  19. $action = $_GET['action'] ?? '';
  20. $help = 'https://www.php.net/manual/en/index.php';
  21. if ($action == 'reset') {
  22. http_response_code(302);
  23. header("Location: /");
  24. die();
  25. } elseif ($action == 'urlencode') {
  26. $result = rawurlencode($str)?: $str;
  27. $help = 'https://www.php.net/rawurlencode';
  28. } elseif ($action == 'urldecode') {
  29. $result = rawurldecode($str)?: $str;
  30. $help = 'https://www.php.net/rawurldecode';
  31. } elseif ($action == 'b64encode') {
  32. $result = base64_encode($str)?: $str;
  33. $help = 'https://www.php.net/base64_encode';
  34. } elseif ($action == 'b64decode') {
  35. $result = base64_decode($str)?: $str;
  36. $help = 'https://www.php.net/base64_decode';
  37. } elseif ($action == 'htmlencode') {
  38. $result = htmlentities($str, ENT_QUOTES | ENT_HTML5)?: $str;
  39. $help = 'https://www.php.net/htmlentities';
  40. } elseif ($action == 'htmldecode') {
  41. $result = html_entity_decode($str, ENT_QUOTES | ENT_HTML5)?: $str;
  42. $help = 'https://www.php.net/html_entity_decode';
  43. } elseif ($action == 'uuencode') {
  44. $result = convert_uuencode($str)?: $str;
  45. $help = 'https://www.php.net/convert_uuencode';
  46. } elseif ($action == 'uudecode') {
  47. $result = convert_uudecode($str)?: $str;
  48. $help = 'https://www.php.net/convert_uudecode';
  49. } elseif ($action == 'hash') {
  50. $result = "Algorithm Time Len Hash\n";
  51. foreach (hash_algos() as $algo) {
  52. $t1 = microtime(true);
  53. $r = hash($algo, $str, false);
  54. $t2 = (microtime(true) - $t1) * 1000;
  55. $result .= sprintf("%-15s %.3f %3d %s\n", $algo, $t2, strlen($r), $r);
  56. }
  57. // password_hash(PASSWORD_DEFAULT)
  58. $t1 = microtime(true);
  59. $r = password_hash($str, PASSWORD_DEFAULT);
  60. $t2 = (microtime(true) - $t1);
  61. $result .= sprintf("%-15s %.3f %3d %s\n", 'password_hash', $t2, strlen($r), $r);
  62. $result = trim($result);
  63. $help = 'https://www.php.net/hash';
  64. } elseif ($action == 'hex') {
  65. $dumper = new Clue\Hexdump\Hexdump();
  66. $result = $dumper->dump($str);
  67. $help = 'https://github.com/clue/php-hexdump';
  68. } elseif ($action == 'qprintencode') {
  69. $result = quoted_printable_encode($str)?: $str;
  70. $help = 'https://www.php.net/quoted_printable_encode';
  71. } elseif ($action == 'qprintdecode') {
  72. $result = quoted_printable_decode($str)?: $str;
  73. $help = 'https://www.php.net/quoted_printable_decode';
  74. }
  75. ?><!doctype html>
  76. <html lang="en">
  77. <head>
  78. <script async src="https://www.googletagmanager.com/gtag/js?id=UA-70198-12"></script>
  79. <script>
  80. window.dataLayer = window.dataLayer || [];
  81. function gtag() { dataLayer.push(arguments) }
  82. gtag('js', new Date());
  83. gtag('config', 'UA-70198-12');
  84. </script>
  85. <meta charset="utf-8">
  86. <meta name="description" content="Encode and Decode strings from/to URL, Base64, HTML entities, UU, Quprint, hash, hex and more." />
  87. <title>Encode/Decode everything</title>
  88. <meta name="description" content="Encode/Decode everything, base64, url, html, charset">
  89. <meta name="author" content="Sergio Álvarez <xergio@gmail.com>">
  90. <!-- <link rel="stylesheet" href="https://unpkg.com/normalize.css@8.0.1/normalize.css"> -->
  91. <link rel="stylesheet" href="https://unpkg.com/spectre.css@0.5.8/dist/spectre.min.css">
  92. <style type="text/css">
  93. html, body { height: 100%; }
  94. body { margin: 0; }
  95. textarea.form-input { width: 100%; height: 80vh; font-family: monospace; }
  96. .container { padding-top: .4rem; padding-bottom: .4rem; }
  97. </style>
  98. </head>
  99. <body class="bg-gray">
  100. <form method="get">
  101. <div class="container">
  102. <?php foreach ($buttons as $act => $label) { ?>
  103. <button type="submit" name="action" value="<?=$act?>" class="btn<?=($action == $act? ' btn-primary': '')?>"><?=$label?></button>
  104. <?php } ?>
  105. <a href="/" class="btn btn-link btn-error">Reset</button>
  106. <a href="<?=$help?>" class="btn btn-link">Help</a>
  107. </div>
  108. <div class="container">
  109. <textarea name="str" class="form-input" placeholder="Paste a string here"><?=htmlentities($result, ENT_QUOTES | ENT_HTML5 | ENT_IGNORE)?></textarea>
  110. </div>
  111. </form>
  112. <div class="container text-right">
  113. <small>Contact me via <a href="mailto:xergio@gmail.com">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://picturepan2.github.io/spectre/">Spectre</a>. <a href="https://sergio.am/code/dencode.xrg.es">Code</a>.</small>
  114. </div>
  115. </body>
  116. </html>