PHP调用FCKEditor和CKEditor

PHP页面:
/* 编辑器 */
include_once "../include/fckeditor/fckeditor.php";//把编辑器引进来
$editor = new FCKeditor('content');//表单项的名称
$editor->BasePath   = "/fckeditor/";//编辑器所在目录
$editor->ToolbarSet = "Normal";//工具栏的名字,可以根据自己的需求加载其他的
$editor->Width      = "95%";//宽度度
$editor->Height     = "250";//高度
$editor->Value      = $content;//初始值
$fckeditor = $editor->CreateHtml();//在要显示编缉器的地方输出变量$fckeditor的值就行了
$tpl->assign('fckeditor', $fckeditor);//模板赋值

HTML模板页面(我用的是smarty)
{%$fckeditor%}


一般php页面调用
content 是我定义的变量名
$content            =$_POST["content"];
添加:
<INPUT name="content" id="content"  type=hidden>
<IFRAME id="content" src="fckeditor/editor/fckeditor.html?InstanceName=content&Toolbar=Normal" frameBorder=0 width=100% scrolling=no height=300 ></IFRAME>
修改页面:

<INPUT name="content" id="content"  type=hidden value="<?php echo  $rows['content'];?>">
<IFRAME id="content" src="/fckeditor/editor/fckeditor.html?InstanceName=content&Toolbar=Normal" frameBorder=0 width=100% scrolling=no height=300 >

</IFRAME>


现在FCK用的少, 用升级到现在的CKEditor.

调用CKEditor:

CKEDITOR的使用很简单,先download CKEDITOR 3.6.1(默认是PHP版的),然后在调用页面的head中,写下如下两段js:

<script type=”text/javascript” src=”ckeditor/ckeditor.js”></script>
<script type=”text/javascript”>                                                                                     window.onload = function()

        {
         CKEDITOR.replace( ‘content’ );
        };

</script>

注意:这里的content是<textarea>的名称,如下所示:

<textarea name=”content”>ddd</textarea>如果是3.6.2版本,该语句可能要写成:

<textarea name=”content” class=”ckeditor”>ddd</textarea>版本差异造成的问题,请大家在运行时注意这个问题。

在下一个页面根据name为content获取相应的值。


通过PHP创建CKEditor表单:

<?php
include_once "ckeditor/ckeditor.php";

// Create a class instance.
$CKEditor = new CKEditor();

// Path to the CKEditor directory.
$CKEditor->basePath = '/ckeditor/';

// Create a textarea element and attach CKEditor to it.
$CKEditor->editor("textarea_id", "This is some sample text");
?>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
相对虚拟站点http://localhost/ictech/ 一、精简说明: 删除所有"_"开头的文件和文件夹 删除语言包中除中文和英文以外的语言 删除skin目录下除默认皮肤以外的文件夹 filemanager/browser/default/connectors/目录下除php以外的文件 filemanager/upload/目录下除php以外的文件 二、配置说明: 将Fckeditor 里的保留文件拷贝到网站根目录文件夹里,即/ictech/下 /fcktemplates.xml /fckstyles.xml /fckeditor_php5.php /fckeditor_php4.php /fckeditor.php /fckeditor.js /fckconfig.js /editor/ fckeditor.php : BasePath为默认Fckeditor的目录,也可以在调用的时候指定. 三、\fckconfig.js 语言识别设置: FCKConfig.AutoDetectLanguage = false ; //61行 关闭自动语言识别 FCKConfig.DefaultLanguage = 'zh-cn' ; //62行 选择 zh-cn 四、上传设置: \editor\filemanager\browser\default\connectors\php\config.php: $Config['Enabled'] = true ;// 30行 是否允许上传 $Config['UserFilesPath'] = '/ictech/userfiles/' ; //33行 默认上传路径,可以更改但必须在相应的目录下建这个名称的目录。 四、上传文件随机重命名为 201447202465.jpg 修改fckeditor/editor/filemanager/connectors/php/commands.php 1.第一段添加函数 [24行] function GetRandID($prefix) { //第一步:初始化种子 //microtime(); 是个数组 $seedstr =split(" ",microtime(),5); $seed =$seedstr[0]*10000; //第二步:使用种子初始化随机数发生器 srand($seed); //第三步:生成指定范围内的随机数 $random =rand(1,10000); $filename = date("dHis", time()).$random.'.'.$prefix; return $filename; } 2.[204行]应用函数 在函数function FileUpload( $resourceType, $currentFolder, $sCommand ) 中的if ( isset( $Config['SecureImageUploads'] ) )[行204]上面一行添加 $sOriginalFileName = $sFileName = GetRandID($sExtension); 设置完成 其他方面设置 ,请参见 http://www.jb51.net/article/12647.htm 五、php文件应用 事例 http://localhost/ictech/fadd.php <?php include("fckeditor.php"); $sBasePath="/ictech/";//编辑器所在目录 $oFCKeditor=new FCKeditor('fileinfo'); // 创建一个fckeditor对象 $oFCKeditor->BasePath=$BasePath; $oFCKeditor->Value=$fileinfo; // 设置表单初始值 $oFCKeditor->Create(); // 调用类中方法,必须 ?>

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值