本手册由zengl开源网的站长提供 首页:www.zengl.com 由于作者是学PHP的,所以就先说哈PHP加载FCKEDITOR的方式。其他的语言等以后有时间再说。 PHP It is very easy to use FCKeditor in your php we...

本手册由zengl开源网的站长提供 首页:www.zengl.com

由于作者是学PHP的,所以就先说哈PHP加载FCKEDITOR的方式。其他的语言等以后有时间再说。

PHP

It is very easy to use FCKeditor in your php web pages. Just follow these steps.  使用PHP加载FCKeditor很容易,只需下面几步:

Integration step by step 

Step 1 步骤1

The first thing to do is to include the "PHP Integration Module" file in the top of your page as in the example below:
第一件事和js一样就是 加载php脚本文件。下面的脚本文件fckeditor.php文件里面会先判断是PHP4还是PHP5,并分别加载 fckeditor_php4.php 和fckeditor_php5.php 文件,这两个文件里定义了 FCKeditor类的结构。

<?php
include_once("fckeditor/fckeditor.php") ;
?>

 

Of course the include path refers to the place where you have installed your FCKeditor.  当然这里的 include 路径要参考你安装的FCKeditor的路径。

Step 2  步骤2

Now the FCKeditor is available and ready to use. So, just insert the following code in your page to create an instance of the editor inside a <FORM>: 现在FCKeditor类库已经可用了,所以只需在您php页面的 <form>标签里插入下面的代码就可以创建一个编辑器的实例了。

  <?php
$oFCKeditor = new FCKeditor('FCKeditor1') ;
$oFCKeditor->BasePath = '/fckeditor/' ;
$oFCKeditor->Value = '<p>This is some <strong>sample text</strong>. You are using <a href="http://www.fckeditor.net/">FCKeditor</a>.</p>' ;
$oFCKeditor->Create() ;
?>

 上面的 Value 是创建编辑器时,编辑器里的默认文本内容。

Step 3 步骤3

The editor is now ready to be used. Just open the page in your browser to see it at work.现在编辑器已经准备就绪,在浏览器中打开页面查看效果。

Complete Sample 完整的示例:

  <?php
include_once("fckeditor/fckeditor.php") ;
?>
<html>
<head>
  <title>FCKeditor - Sample</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
  <form action="sampleposteddata.php" method="post" target="_blank">
<?php
$oFCKeditor = new FCKeditor('FCKeditor1') ;
$oFCKeditor->BasePath = '/fckeditor/' ;
$oFCKeditor->Value = '<p>This is some <strong>sample text</strong>. You are using <a href="http://www.fckeditor.net/">FCKeditor</a>.</p>' ;
$oFCKeditor->Create() ;
?>
    <br>
    <input type="submit" value="Submit">
  </form>
</body>
</html>

"FCKeditor1" is the name used to post the editor data on forms.  在FORM中 提交数据时,可以使用 FCKeditor1作为变量名来获取编辑器中的数据。

Configuration Options    参数配置

You can pass Configuration Options using the Config array. This way you can overwrite the default setting from fckconfig.js for selected users.     你可以使用Config 数组来传递 与编辑器相关的配置参数,通过这种方法 你可以覆盖fckconfig.js 脚本中的默认设置,以满足不同用户的需求。

  <?php
$oFCKeditor = new FCKeditor('FCKeditor1') ;
$oFCKeditor->BasePath = '/fckeditor/' ;

//set the EnterMode to "br" (overwrites the default configuration from fckconfig.js)
$oFCKeditor->Config['EnterMode'] = 'br';  //默认情况下 按回车 会转化为 p 段落。但是 <p> 标签在html显示时空行太多,
只有同时按 shift+enter 才能得到 br ,所以可以在这个数组中将这两种默认方式交互哈,就可以方便使用了。

$oFCKeditor->Value = '<p>This is some <strong>sample text</strong>. You are using <a href="http://www.fckeditor.net/">FCKeditor</a>.</p>' ;
$oFCKeditor->Create() ;
?>

Handling the posted data 操作上传的数据

The editor instance just created will behave like a normal <INPUT> field in a form. It will use the name you've used when creating it (in the above sample, "FCKeditor1"). So, if you have magic quotes enabled, retrieve its value by doing something like this:  刚刚创建的编辑器实例可以像form中的普通的input 元素一样工作,该编辑器会使用您刚提供给它的名字 作为他自己的name 值 。在上面的例子中就是 "FCKeditor1" 。所以,你可以参照下面的方式取得该编辑器上传的内容。下面的代码是建立在您开启了php “魔术引号”的功能的基础上的(魔术引号(magic quotes)是一个自动将进入 PHP 脚本的数据进行转义的过程。最好在编码时不要转义而在运行时根据需要而转义。当打开时,所有的 '(单引号),"(双引号),反斜杠和 NULL 字符都会被自动加上一个反斜线进行转义。这和addslashes()函数的作用完全相同。所以下面的代码就需要使用 stripslashes 函数去除转义字符,才能得到编辑器中真实的值)。

$sValue = stripslashes( $_POST['FCKeditor1'] ) ;

Additional information   附加信息

  • You can find some samples on how to use the editor in the "_samples/php" directory of the distributed package.

 您可以在 “_samples/php” 目录中找到一些例子 ,这些例子说明了如何用PHP 来加载编辑器。

OK,本章结束,休息,休息哈。

如果本文有翻译不周的地方,或有其他方面的评论,可以到下方发表评论。

上下篇

下一篇: FCKeditor编辑器的配置文件

上一篇: JavaScript脚本加载fckeditor编辑器

相关文章

FCKeditor脚本压缩

FCKeditor的拼写检查器

FCKeditor的开发精简

FCKeditor自定义文件浏览器

FCKeditor的安装

FCKeditor的皮肤设置