調用 FCKeditor 必須先載入 FCKeditor 類文件。
具體代碼如下。
<?php include("fckeditor/fckeditor.php") ; // 用於載入 FCKeditor 類文件 ?>
接下來,我們需要創建 FCKeditor 實例、指定 FCKeditor 存放路徑和創建(顯示)編輯器等。 具體代碼如下所示(代碼一般放在表單內) 。
<?php $oFCKeditor = new FCKeditor('FCKeditor1') ; // 創建 FCKeditor 實例
$oFCKeditor->BasePath = './fckeditor/'; // 設置 FCKeditor 目錄地址
$FCKeditor->Width='100%'; //設置顯示寬度 $FCKeditor->Height='300px'; //設置顯示高度的高度
$oFCKeditor->Create() ; // 創建編輯器 ?>
下面是筆者創建好的實例代碼,您可將代碼保存爲 add_article.php。
<?php include("fckeditor/fckeditor.php") ; // 用於載入 FCKeditor 類文件 ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>用 PHP 調用 FCKeditor</title>
</head>
<body>
<form action="check.php" method="post" name="exapmle">
<?php $oFCKeditor = new FCKeditor('FCKeditor1') ; // 創建 FCKeditor 實例,可創建多個實例
$oFCKeditor->BasePath = './fckeditor/'; // 設置 FCKeditor 目錄地址
$oFCKeditor->Create() ; // 創建編輯器 ?>
<input name="ok" type="submit" value="提交" >
</form>
</body>
</html>
通過瀏覽裏打開 http://you-address/add_article.php 查看 FCKeditor 安裝效果。