function copySample(){ var a = document.getElementById('sample'); var b = document.getElementById('input'); if (a != null){ b.value = a.value; } } function clearInput(){ var b = document.getElementById('input'); b.value = ''; } "; print "
Input (any format)

Sample text.

Put any formatted text (text, Base64, binary, hex, or decimal) in the input box on the left.

It will be encoded or decoded in the boxes below.

You can then copy from any box in the left two columns, into the input box, and it will decode.

This is useful for when someone posts a blob of binary or other unknown formats, to automatically decode it.

This should support all UTF-8 characters.

You can use this code to learn from. There are a bunch of different UTF-8 CPs in the source. Make sure your editor can handle UTF-8 before saving it.
There are only two important files.
converter.php and converter_functions.php.
Output
(invalid conversions will show garbage, or nothing)
Text ⯈ Base64
Text ⯈ Base64 (RFC 2045 lines)
Base64 ⯈ Text
Text ⯈ Hex
Text ⯈ Hex padded
  Hex ⯈ Text
  Text ⯈ Dec padded
  Dec ⯈ Text
Text ⯈ Binary
Text ⯈ Binary padded
  Binary ⯈ Text
"; // Footer, just for my site. include_once("../../footer.php"); // ********** FUNCTIONS ********** // function bin2txt_8bit($in){ // We need to strip the spaces, if this is padded data. // Also, remove any other characters, since binary doesn't have anything but 0/1. $in = preg_replace("/[^01]+/","",$in); $in = ltrim(rtrim($in)); $out = ''; $pcs = explode("\n", chunk_split($in,8)); #print "Pieces
" . print_r($pcs, TRUE) . "
"; foreach ($pcs as $thispc){ if ($thispc != ''){ #print "PC " . bindec($thispc) . "
"; #print "CR " . chr(bindec($thispc)) . "
"; $out .= chr(bindec($thispc)); }; }; $out = urldecode(urlencode($out)); return($out); }; function txt2bin_8bit($in, $padding){ $pcs = preg_split('//', $in, -1, PREG_SPLIT_NO_EMPTY); $out = ''; #print "Pieces
" . print_r($pcs, TRUE) . "
"; foreach ($pcs as $thispc){ #print "ord " . ord($thispc) . "
"; $out .= sprintf("%08d", decbin(ord($thispc))); if($padding == 1){ $out .= " "; }; }; return($out); }; function text2hex($in, $padding){ //bin2hex($in) $pcs = preg_split('//', $in, -1, PREG_SPLIT_NO_EMPTY); $out = ''; foreach ($pcs as $thispc){ $out .= bin2hex($thispc); if($padding == 1){ $out .= " "; }; }; return($out); }; function hex2text($in){ // We need to strip the spaces, if this is padded data. // Also, remove any other characters, since hex doesn't have anything but 0123456789abcdef. // hex2bin($in) // hex2bin gracefully handles an entire string, it doesn't have to be chunked. // A valid input will have an even number of characters. We're padding, // just in case they copied a portion of a valid string. $in = preg_replace("/[^0-9a-f]+/","",$in); $numchar = strlen($in); if($numchar % 2 == 0){ // even, don't modify. #print "Even"; }else{ // odd, pad with a zero. #print "Odd"; $in = $in . "0"; }; $out = hex2bin($in); return($out); }; function text2dec($in, $padding=1){ // Because of UTF8 characters, the dec number can be really big. // We can't zero pad to extract later, so I'm forcing space padding. // There's probably a better way to do it. If found, this will be fixed. // Needless to say, this probably isn't very portable. //bin2hex($in) //$pcs = preg_split('//', $in, -1, PREG_SPLIT_NO_EMPTY); $pcs = preg_split('//u', $in, -1, PREG_SPLIT_NO_EMPTY); $out = ''; //print "text2dec Pieces
" . print_r($pcs, TRUE) . "
"; foreach ($pcs as $thispc){ //$out .= sprintf("%03d", mb_ord($thispc, "UTF-8")); $out .= mb_ord($thispc, "UTF8"); if($padding == 1){ $out .= " "; }; }; return($out); }; function dec2text($in){ // We need to strip the spaces, if this is padded data. // Also, remove any other characters, since dec doesn't have anything but 0123456789. $in = preg_replace("/[^0-9\ ]+/","",$in); // chr doesn't handle entire strings. It must be by character. $in = ltrim(rtrim($in)); $out = ''; #$pcs = explode("\n", chunk_split($in,3)); $pcs = explode(" ", $in); foreach ($pcs as $thispc){ #if (!empty($thispc)){ #if (is_numeric($thispc)){ // Uncaught TypeError: mb_chr(): Argument #1 ($codepoint) must be of type int, string given #if (is_numeric($thispc)){ $thispc = intval($thispc); $out .= mb_chr($thispc); #}; }; return($out); };