功能特色
- 支援字串 Base64 編碼與解碼
- 解碼時自動處理 UTF-8 → GB2312 轉碼 (GB2312 版)
- 內建原始碼下載功能 (
?down=1)
- 純單檔 PHP + HTML,免資料庫,即刻部署
核心 PHP 邏輯
<?php
header('Content-Type: text/html; charset=gb2312');
$txt1 = stripslashes(trim(@$_POST['text1']));
$button = @$_POST['button'];
$down = @trim($_GET['down']);
if ($down == 1) {
header("Content-type: command");
header("Content-Disposition: attachment; filename=base64_decode.txt");
echo file_get_contents(basename($_SERVER['PHP_SELF']));
exit;
}
?>
前端表單與即時轉換
<form name="form1" method="post" action="">
<h1>Base64在線編碼解碼 gb2312 <a href="?down=1">源碼下載</a></h1>
<p>
請輸入轉換的內容:
<textarea name="text1" rows="14" class="bginput" style="width:520px;"><?php echo htmlspecialchars($txt1, ENT_QUOTES); ?></textarea>
<br>
轉換結果:
<textarea rows="14" class="bginput" style="width:520px;"><?php
if ($button == "編碼") echo base64_encode($txt1);
if ($button == "解碼") echo mb_convert_encoding(base64_decode($txt1), "gb2312", "UTF-8");
?></textarea>
<br>
<input type="submit" name="button" class="button" value="編碼" />
<input type="submit" name="button" class="button" value="解碼" />
</p>
</form>
部署說明
- 儲存為
base64_decode-gb2312.php (Big5/GB2312 專案) 或修改 charset 為 UTF-8 版。
- 確保 PHP 啟用
mbstring 擴充 (解碼轉碼需用)。
- 放入網站任意目錄,瀏覽器直接存取即可使用。
線上演示 (原文連結)
- GB2312 版:
https://tools.jb51.net/tools/base64_decode-gb2312.php
- UTF-8 版:
https://tools.jb51.net/tools/base64_decode-utf8.php