天天看點

FCKeditor 應用

FCKeditor使用方法小結(php)

标簽:學習筆記  php  fckeditor使用  

  最近用php+mysql開發一個項目,裡面用到了FCKeditor,下面對這個用法進行一下小結.首先說明一下我的FCKeditor版本是2.1多國語言版.

  用法:1.我的網站目錄是www.裡面有如下檔案夾和檔案

  /www

      add.php

      /include

      /FCKeditor

        2.調用FCKeditor的方法:

          (1)在開頭包含include("FCKeditor/fckeditor.php")

          (2)在需要使用的的方加入

           <?php

            $oFCKeditor = new FCKeditor('FCKeditor1') ;//建立對象

            $oFCKeditor->BasePath = 'FCKeditor/' ;//FCKeditor所在的位置

            $oFCKeditor->ToolbarSet = 'Default' ;//工具按鈕

            $oFCKeditor->Create('EditorDefault', '60%',150) ;

           ?> 

            (此處basepath的路徑一定要和上面include的路徑一樣.否則會找不到檔案)

            另外,對于這個輸入内容的變量,如果要把它存入資料庫,它的變量名為你建

            立對象的名字.例如上面就是FCKeditor1 

         3.在FCKeditor/_samples/裡面有個php調用的例子.如simples01.php

           和sampleposteddata.php這兩個.後面那個檔案是輸出變量名的php

           程式,通過這個程式可以得到文本輸入框内容的變量名.

         4.配置 FCKeditor的toolbar功能按鈕可以很容易地進行定制,你可以依據你

           的需要在FCKeditor的配置檔案FCKeditor/fck_config.js中進行定制

           ,一個功能按鈕對應一個唯一的名稱。 

           在fck_config.js中預設情況下已經設定好三種toolbar樣式:Default(包

           含全部功能),Accessibility和Basic。

讓我們先來看看toolbar樣式的定制格式:

config.ToolbarSets["ToolBarSetName"] = [ // Toolbar名

['Item 1','Item 2','-','Item 3','Item n'], // Toolbar第一行

['Item 4','-','Item 5','Item 6','Item n'] // Toolbar第二行

] ;

這裡'-'的作用是建立一個分割條。

FCKeditor1.6為我們提供了60個編輯功能,具體功能如下: 

    預設的Default包含了FCKeditor的全部功能,個人感覺有些功能用不上,完全加載還會影響顯示速度,是以我簡化了一下,隻加載了一些常用的功能:

1、打開FCKeditor/fck_config.js檔案,添加如下代碼

config.ToolbarSets["www"] = [

['EditSource','Save','NewPage','Preview','-','Cut','Copy','Paste','PasteText','-','Find','Replace','-','Undo','Redo','-','SelectAll','-','Link','RemoveLink','-','Image','Table','Rule','SpecialChar','Smiley'] ,

['Bold','Italic','Underline','-','JustifyLeft','JustifyCenter','JustifyRight','-','InsertOrderedList','InsertUnorderedList','-','Form','Checkbox','Radio','Input','Textarea','Select','Button','-','FontStyleAdv','TextColor'] ] ; 

  這樣加載的速度就快多了。

  使用時隻需把$oFCKeditor->ToolbarSet = 'Default' 

  改為$oFCKeditor->ToolbarSet = 'www' 即可

功能名稱 含義 功能名稱 含義
EditSource 顯示HTML源代碼 StrikeThrough 删除線
Save 儲存 Subscript 下标
NewPage 建立空白頁面 Superscript 上标
Preview 預覽 JustifyLeft 左對齊
Cut 剪切 JustifyCenter 居中對齊
Copy 複制 JustifyRight 右對齊
Paste 粘貼 JustifyFull 兩端對齊
PasteText 純文字粘貼 InsertOrderedList 自動編号
PasteWord 來自Word的粘貼 InsertUnorderedList 項目符号
Print 列印 Outdent 減少縮進
SpellCheck 拼寫檢查 Indent 增加縮進
Find 查找 ShowTableBorders 顯示表格線
Replace 替換 ShowDetails 顯示明細
Undo 撤銷 Form 添加Form動作
Redo 還原 Checkbox 複選框
SelectAll 全選 Radio 單選按鈕
RemoveFormat 去除格式 Input 單行文本框
Link 插入/編輯 連結 Textarea 滾動文本框
RemoveLink 去除連接配接 Select 下拉菜單
Anchor 錨點 Button 按鈕
Image 插入/編輯 圖檔 ImageButton 圖檔按鈕
Table 插入/編輯 表格 Hidden 隐藏
Rule 插入水準線 Zoom 顯示比例
SpecialChar 插入特殊字元 FontStyleAdv 系統字型
UniversalKey 軟鍵盤 FontStyle 字型樣式
Smiley 插入表情符号 FontFormat 字型格式
About 關于 Font 字型
Bold 粗體 FontSize 字型大小
Italic 斜體 TextColor 文字顔色
Underline 下劃線 BGColor 背景色

ASP 的配置方法

在站點根目錄下,建立一個index.asp頁面,<body>段内加如下代碼(調用編輯器):

<%

Dim oFCKeditor

 Set oFCKeditor = New FCKeditor

 oFCKeditor.BasePath = "/FCKeditor/"  //設定編輯器的路徑,我站點根目錄下的一個目錄

 oFCKeditor.ToolbarSet = "Default"

 oFCKeditor.Width = "100%"

 oFCKeditor.Height = "600"

 oFCKeditor.Value = "" //這個是給編輯器初始值

 oFCKeditor.Create "logbody" //以後編輯器裡的内容都是由這個logbody取得,命名由你定

 %>

加了這一段别忘了在index.asp前面第二行加上

<!--#include file="FCKeditor/fckeditor.asp" -->

把fckeditor.asp包含進來。切記切記!

就這麼簡單!

現在你隻要把這個編輯器當成一個控件來使用,提取它的資料時用:request("logbody")

現在松口氣吧。測試成功了。裡面有些設定,去網上找些進階的使用說明來看吧。

《檸檬園主》的進階說明。我又從這裡獲得了幫助。

http://3rgb.com/b/?act=viewthread&threadid=324