首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 網頁程式設計 >> PHP 程式設計 >> PHP 綜合知識

Base64 線上編碼/解碼工具完整原始碼 (支援 GB2312/UTF-8 雙版本)

     編輯:PHP 綜合知識

功能特色

  • 支援字串 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>

部署說明

  1. 儲存為 base64_decode-gb2312.php (Big5/GB2312 專案) 或修改 charset 為 UTF-8 版。
  2. 確保 PHP 啟用 mbstring 擴充 (解碼轉碼需用)。
  3. 放入網站任意目錄,瀏覽器直接存取即可使用。

線上演示 (原文連結)

  • GB2312 版:https://tools.jb51.net/tools/base64_decode-gb2312.php
  • UTF-8 版:https://tools.jb51.net/tools/base64_decode-utf8.php
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved