FCKeditor(現更名為 CKEditor)是經典的網頁富文本編輯器。本文記錄 PHP 後端實例化與前端 JavaScript 直接調用的完整配置參數,適用於舊專案維護或快速原型開發。
適合在伺服器端動態決定工具列、尺寸、皮膚等配置:
<?php
require_once(PATH_PRE . "fckeditor.php"); // 載入核心類別
$oFCKeditor = new FCKeditor('content'); // 表單欄位名稱
$oFCKeditor->BasePath = "../fckeditor/"; // 編輯器資源目錄(相對或絕對路徑)
$oFCKeditor->ToolbarSet = "Yiyunnet"; // 工具列配置名稱
$oFCKeditor->Height = '100%';
$oFCKeditor->Width = '100%';
$oFCKeditor->Value = ""; // 初始內容
// 選用配置
$oFCKeditor->Config['SkinPath'] = '../editor/skins/silver/'; // 皮膚路徑
$oFCKeditor->Create(); // 輸出編輯器 HTML
?>
| 名稱 | 特點 |
|---|---|
| Basic | 基礎工具(粗體、斜體、連結等) |
| Default | 完整工具列 |
| Soft | 單欄,可插入圖片/影片 |
| Renpeng | 雙欄,可上傳圖片/影片 |
| Full | 三欄完整功能 |
無需 PHP 參與,適合純前端頁面或 SPA 架構:
<script src="fckeditor/fckeditor.js"></script>
<script type="text/javascript">
var oFCKeditor = new FCKeditor('Content');
oFCKeditor.BasePath = 'fckeditor/';
oFCKeditor.ToolbarSet = 'Basic';
oFCKeditor.Width = '100%';
oFCKeditor.Height = '400';
oFCKeditor.Value = '';
oFCKeditor.Create();
</script>
<script src="fckeditor/fckeditor.js"></script>
<script type="text/javascript">
function showFCK() {
var oFCKeditor = new FCKeditor('Content');
oFCKeditor.BasePath = 'fckeditor/';
oFCKeditor.ToolbarSet = 'Basic';
oFCKeditor.Width = '100%';
oFCKeditor.Height = '200';
oFCKeditor.Value = '';
oFCKeditor.ReplaceTextarea(); // 關鍵:替換同名 textarea
document.getElementById('btnShow').disabled = true;
document.getElementById('btnShow').style.display = 'none';
}
</script>
<textarea name="Content"></textarea>
<input id="btnShow" type="button" value="載入編輯器" onclick="showFCK()" />
優勢:頁面初載不載入編輯器資源,使用者點擊才初始化,提升首屏速度。
| 屬性 | 說明 | 範例值 |
|---|---|---|
| BasePath | 編輯器核心檔案目錄(必須以 / 結尾) | /fckeditor/ |
| ToolbarSet | 工具列配置名稱,對應 fckconfig.js 定義 | Default, Basic, Full |
| Config['SkinPath'] | 皮膚目錄路徑 | ../editor/skins/office2003/ |
| Config['Language'] | 介面語言 | zh-tw, en |
| Config['AutoDetectLanguage'] | 自動偵測瀏覽器語言 | true/false |
| Height / Width | 編輯區域尺寸,支援 px 或 % | 400, '100%' |
FileBrowserUploadUrl 並確保伺服端有上傳處理腳本(如 PHP connector)。Config['EditorAreaCSS'] 指定專用 CSS。FCKeditor 雖已停止維護(繼任者為 CKEditor 4/5),但大量舊系統仍在使用。掌握 PHP 與 JS 兩種整合模式,能靈活應對不同架構需求。新專案建議直接採用 CKEditor 5,擁有更現代的架構與更佳的安全性。