A-A+
fck编辑器php中运用
相信许多 phper 已经在使用 fckeditor 做网页编辑器了,如果还没接触到,那不要紧,在编程的路上,一定会使用到 fckeditor 编辑器的,fckeditor 是一个专门使用在网页上属于开源的所见即所得的文字编辑器,对于 fckeditor 的安装,不需要太多复杂的安装步骤即可使用,fckeditor 编辑器可以很好地与 PHP、JAVASCRIP、ASP、.NET、等不同的网页编程语言相结合,一般我们将 fckeditor 简化称为 FCK 编辑器,除了这款编辑器的轻量级外,这款软件的功能也很强大,在PHP后台开发中是一款必不可缺少的编辑器,也是大多数网站所选择的编辑器,下面看一下 FCK 编辑器在PHP中的应用。
因为 FCK 编辑器功能的强大,所以它的功能属性也很多,作为PHPer开发者,如果不是开发超强的应用,其实我们没必要了解太多繁琐的属性功能,所以在这里我们只介绍最实用的部分,看一下下面的 fck 编辑器在 php 中的运用。
<?php
header("content-type:text/html;charset=utf-8");
$conn=@mysql_connect("localhost","root","123");
mysql_select_db("test");
mysql_query("set names utf8");
$con=$_POST['con'];
if($con!=""){
$sql="insert into fckedit (content) values('$con')";
mysql_query($sql);
}
?>
<script>
//验证fck内容是否为空
function check(){
//取fckeditor的内容
var con=FCKeditorAPI.GetInstance('con').GetXHTML(true);
if(con==""){
alert("不能为空");
return false;
}else
{
return true;
}
//为fckeditor设置内容
FCKeditorAPI.GetInstance('con').SetHTML("没问题了");
return false;
}
</script>
<form action=www.xiariboke.net name="myform" method="post"
onsubmit="return check()">
<?php
include("FCKeditor/fckeditor_php5.php");
$ed=new FCKeditor('con');
$ed->BasePath='FCKeditor/'; //告诉你fck所需要的文件路径
$ed->ToolbarSet='Default';
$ed->Value="这是默认值";
$ed->Width='50%';
$ed->Height='300px';
$ed->create();
?>
<input type="submit" value="提交"/>
</form>
小说明:这就是 fck 编辑器在 php 中运用得最实用的例子了,应用mysql数据库和 fck 很好地进行结合,这里只是一个实例,请注意一下 include("FCKeditor/fckeditor_php5.php"); 这一句,这是包含 fck 编辑器文件的路径,其中 FCKeditor 就是 FCK 编辑器了,快去试一下吧,让自己的网页也加上类似 word 编辑的强大功能。