PHP如何搭建百度Ueditor富文本编辑器

yipeiwu_com7年前PHP代码库

本文为大家分享了PHP搭建百度Ueditor富文本编辑器的方法,供大家参考,具体内容如下

下载UEditor

官网:下载地址

将下载好的文件解压到thinkphp项目中,本文是解压到PUBLIC目录下并改文件夹名称为ueditor

第一步 引入javascript

在html中如入下面的js语句引入相关文件

<script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.config.js"></script> 
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.all.js"></script> 

第二步 添加textare文本域并设置id值

<textarea type="text" name="content" id="EditorId" placeholder="请输入内容"></textarea>

第三步 初始化UEditor编辑器

在html代码中添加下面的代码初始化UEditor编译器

<script type="text/javascript" charset="utf-8">//初始化编辑器 
   window.UEDITOR_HOME_URL = "__PUBLIC__/ueditor/";//配置路径设定为UEditor所放的位置 
   window.onload=function(){ 
    window.UEDITOR_CONFIG.initialFrameHeight=600;//编辑器的高度 
    window.UEDITOR_CONFIG.initialFrameWidth=1200;//编辑器的宽度 
    var editor = new UE.ui.Editor({ 
      imageUrl : '', 
      fileUrl : '', 
      imagePath : '', 
      filePath : '', 
      imageManagerUrl:'', //图片在线管理的处理地址 
      imageManagerPath:'__ROOT__/' 
    }); 
    editor.render("EditorId");//此处的EditorId与<textarea name="content" id="EditorId">的id值对应 </textarea> 
  } 
</script> 

第四步 设置图片上传路径

UEditor编辑器的默认图片上传路径是根目录下/ueditor/php/upload/image/目录,没有这个目录会自动创建,如果要自定义图片上传路径,可以在ueditor/php/config.json文件中12行处修改。

最后贴上完整的html代码:

<!DOCTYPE html> 
<html lang="en"> 
<head> 
  <meta charset="UTF-8"> 
  <title>Document</title> 
  <script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.config.js"></script> 
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.all.js"></script> 
</head> 
<body> 
 
 <form action="__URL__/receiver" method="post" accept-charset="utf-8"> 
  <textarea type="text" name="content" id="EditorId" placeholder="请输入内容"></textarea> 
  <input type="submit" value="提交"> 
 </form> 
   
  <script type="text/javascript" charset="utf-8">//初始化编辑器 
  window.UEDITOR_HOME_URL = "__PUBLIC__/ueditor/";//配置路径设定为UEditor所放的位置 
  window.onload=function(){ 
    window.UEDITOR_CONFIG.initialFrameHeight=600;//编辑器的高度 
    window.UEDITOR_CONFIG.initialFrameWidth=1200;//编辑器的宽度 
    var editor = new UE.ui.Editor({ 
      imageUrl : '', 
      fileUrl : '', 
      imagePath : '', 
      filePath : '', 
      imageManagerUrl:'', //图片在线管理的处理地址 
      imageManagerPath:'__ROOT__/' 
    }); 
    editor.render("EditorId");//此处的EditorId与<textarea name="content" id="EditorId">的id值对应 </textarea> 
  } 
</script> 
</body> 
</html> 

效果图

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持【宜配屋www.yipeiwu.com】。

相关文章

PHP中include与require使用方法区别详解

在PHP变成中,include()与require()的功能相同,include(include_once) 与 require(require_once)都是把把包含的文件代码读入到指...

PHP 7安装调试工具Xdebug扩展的方法教程

PHP 7安装调试工具Xdebug扩展的方法教程

前言 说到PHP代码调试,对于有经验的PHPer,通过echo、print_r、var_dump函数,或PHP开发工具zend studio、editplus可解决大部分问题,但是对于P...

配置eAccelerator和XCache扩展来加速PHP程序的执行

配置eAccelerator和XCache扩展来加速PHP程序的执行

eaccelerator安装配置PHP加速 eAccelerator简介 eAccelerator是一个的免费、开源的PHP模块,它能够为提供PHP加速、优化、加码、和动态内容缓存功能。...

php多进程应用场景实例详解

本文实例讲述了php多进程应用场景。分享给大家供大家参考,具体如下: pcntl介绍 扩展介绍 php多进程模块依赖pcntl扩展,官方手册介绍:http://php.net/manua...

一些需要禁用的PHP危险函数(disable_functions)

phpinfo() 功能描述:输出 PHP 环境信息以及相关的模块、WEB 环境等信息。 危险等级:中 passthru() 功能描述:允许执行一个外部程序并回显输出,类似于 exec(...