composer require clue/php-hexdump for Hex output

This commit is contained in:
Sergio Álvarez 2019-12-11 13:35:54 +01:00
parent 0f296dcefa
commit 75bf293770
3 changed files with 27 additions and 17 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
composer.lock
vendor/

5
composer.json Normal file
View File

@ -0,0 +1,5 @@
{
"require": {
"clue/hexdump": "^0.2.0"
}
}

View File

@ -1,5 +1,7 @@
<?php <?php
require_once 'vendor/autoload.php';
// action => label // action => label
$buttons = [ $buttons = [
'urlencode' => 'URL Encode', 'urlencode' => 'URL Encode',
@ -18,7 +20,7 @@ $buttons = [
$str = $result = $_GET['str'] ?? ''; $str = $result = $_GET['str'] ?? '';
$action = $_GET['action'] ?? ''; $action = $_GET['action'] ?? '';
$help = 'manual/en/index.php'; $help = 'https://www.php.net/manual/en/index.php';
if ($action == 'reset') { if ($action == 'reset') {
http_response_code(302); http_response_code(302);
@ -26,36 +28,36 @@ if ($action == 'reset') {
die(); die();
} elseif ($action == 'urlencode') { } elseif ($action == 'urlencode') {
$result = urlencode($str)?: $str; $result = rawurlencode($str)?: $str;
$help = 'urlencode'; $help = 'https://www.php.net/rawurlencode';
} elseif ($action == 'urldecode') { } elseif ($action == 'urldecode') {
$result = urldecode($str)?: $str; $result = rawurldecode($str)?: $str;
$help = 'urldecode'; $help = 'https://www.php.net/rawurldecode';
} elseif ($action == 'b64encode') { } elseif ($action == 'b64encode') {
$result = base64_encode($str)?: $str; $result = base64_encode($str)?: $str;
$help = 'base64_encode'; $help = 'https://www.php.net/base64_encode';
} elseif ($action == 'b64decode') { } elseif ($action == 'b64decode') {
$result = base64_decode($str)?: $str; $result = base64_decode($str)?: $str;
$help = 'base64_decode'; $help = 'https://www.php.net/base64_decode';
} elseif ($action == 'htmlencode') { } elseif ($action == 'htmlencode') {
$result = htmlentities($str, ENT_QUOTES | ENT_HTML5)?: $str; $result = htmlentities($str, ENT_QUOTES | ENT_HTML5)?: $str;
$help = 'htmlentities'; $help = 'https://www.php.net/htmlentities';
} elseif ($action == 'htmldecode') { } elseif ($action == 'htmldecode') {
$result = html_entity_decode($str, ENT_QUOTES | ENT_HTML5)?: $str; $result = html_entity_decode($str, ENT_QUOTES | ENT_HTML5)?: $str;
$help = 'html_entity_decode'; $help = 'https://www.php.net/html_entity_decode';
} elseif ($action == 'uuencode') { } elseif ($action == 'uuencode') {
$result = convert_uuencode($str)?: $str; $result = convert_uuencode($str)?: $str;
$help = 'convert_uuencode'; $help = 'https://www.php.net/convert_uuencode';
} elseif ($action == 'uudecode') { } elseif ($action == 'uudecode') {
$result = convert_uudecode($str)?: $str; $result = convert_uudecode($str)?: $str;
$help = 'convert_uudecode'; $help = 'https://www.php.net/convert_uudecode';
} elseif ($action == 'hash') { } elseif ($action == 'hash') {
$result = "Algorithm Time Len Hash\n"; $result = "Algorithm Time Len Hash\n";
@ -73,19 +75,20 @@ if ($action == 'reset') {
$result .= sprintf("%-15s %.3f %3d %s\n", 'password_hash', $t2, strlen($r), $r); $result .= sprintf("%-15s %.3f %3d %s\n", 'password_hash', $t2, strlen($r), $r);
$result = trim($result); $result = trim($result);
$help = 'hash'; $help = 'https://www.php.net/hash';
} elseif ($action == 'hex') { } elseif ($action == 'hex') {
$result = chunk_split(bin2hex($str), 2, " "); $dumper = new Clue\Hexdump\Hexdump();
$help = 'bin2hex'; $result = $dumper->dump($str);
$help = 'https://github.com/clue/php-hexdump';
} elseif ($action == 'qprintencode') { } elseif ($action == 'qprintencode') {
$result = quoted_printable_encode($str)?: $str; $result = quoted_printable_encode($str)?: $str;
$help = 'quoted_printable_encode'; $help = 'https://www.php.net/quoted_printable_encode';
} elseif ($action == 'qprintdecode') { } elseif ($action == 'qprintdecode') {
$result = quoted_printable_decode($str)?: $str; $result = quoted_printable_decode($str)?: $str;
$help = 'quoted_printable_decode'; $help = 'https://www.php.net/quoted_printable_decode';
} }
?><!doctype html> ?><!doctype html>
@ -123,7 +126,7 @@ if ($action == 'reset') {
<button type="submit" name="action" value="<?=$act?>" class="btn<?=($action == $act? ' btn-primary': '')?>"><?=$label?></button> <button type="submit" name="action" value="<?=$act?>" class="btn<?=($action == $act? ' btn-primary': '')?>"><?=$label?></button>
<?php } ?> <?php } ?>
<a href="/" class="btn btn-link btn-error">Reset</button> <a href="/" class="btn btn-link btn-error">Reset</button>
<a href="https://php.net/<?=$help?>" class="btn btn-link">Help</a> <a href="<?=$help?>" class="btn btn-link">Help</a>
</div> </div>
<div class="container"> <div class="container">