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
require_once 'vendor/autoload.php';
// action => label
$buttons = [
'urlencode' => 'URL Encode',
@ -18,7 +20,7 @@ $buttons = [
$str = $result = $_GET['str'] ?? '';
$action = $_GET['action'] ?? '';
$help = 'manual/en/index.php';
$help = 'https://www.php.net/manual/en/index.php';
if ($action == 'reset') {
http_response_code(302);
@ -26,36 +28,36 @@ if ($action == 'reset') {
die();
} elseif ($action == 'urlencode') {
$result = urlencode($str)?: $str;
$help = 'urlencode';
$result = rawurlencode($str)?: $str;
$help = 'https://www.php.net/rawurlencode';
} elseif ($action == 'urldecode') {
$result = urldecode($str)?: $str;
$help = 'urldecode';
$result = rawurldecode($str)?: $str;
$help = 'https://www.php.net/rawurldecode';
} elseif ($action == 'b64encode') {
$result = base64_encode($str)?: $str;
$help = 'base64_encode';
$help = 'https://www.php.net/base64_encode';
} elseif ($action == 'b64decode') {
$result = base64_decode($str)?: $str;
$help = 'base64_decode';
$help = 'https://www.php.net/base64_decode';
} elseif ($action == 'htmlencode') {
$result = htmlentities($str, ENT_QUOTES | ENT_HTML5)?: $str;
$help = 'htmlentities';
$help = 'https://www.php.net/htmlentities';
} elseif ($action == 'htmldecode') {
$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') {
$result = convert_uuencode($str)?: $str;
$help = 'convert_uuencode';
$help = 'https://www.php.net/convert_uuencode';
} elseif ($action == 'uudecode') {
$result = convert_uudecode($str)?: $str;
$help = 'convert_uudecode';
$help = 'https://www.php.net/convert_uudecode';
} elseif ($action == 'hash') {
$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 = trim($result);
$help = 'hash';
$help = 'https://www.php.net/hash';
} elseif ($action == 'hex') {
$result = chunk_split(bin2hex($str), 2, " ");
$help = 'bin2hex';
$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 = 'quoted_printable_encode';
$help = 'https://www.php.net/quoted_printable_encode';
} elseif ($action == 'qprintdecode') {
$result = quoted_printable_decode($str)?: $str;
$help = 'quoted_printable_decode';
$help = 'https://www.php.net/quoted_printable_decode';
}
?><!doctype html>
@ -123,7 +126,7 @@ if ($action == 'reset') {
<button type="submit" name="action" value="<?=$act?>" class="btn<?=($action == $act? ' btn-primary': '')?>"><?=$label?></button>
<?php } ?>
<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 class="container">