ThinkPHP框架中使用富文本编辑器后如何输出

htmlspecialchars_decode()用这个能解析里面的符号

我们在利用ThinkPHP提交数据的时候,数据库里的数据是含各种html标签的,那么在输出时就可以直接输出嘛。但是,也许你的老师曾经告诉过你,在进行后台数据提交的时候,要过滤掉html标签,如I('content','','htmlspecialchars ')这样来操作的。但是经过这样的过滤后,你要是还想直接输出来或是进行截取字符的时候就会遇到很多的麻烦。本人经过多次摸索的实验,得来以下经验,希望分享了可以帮助到大家。

总结:

在运用富文本提交数据时,为了在数据输出时能够正常显示,有以下几种方法:

1、在接收数据时采用如I('content','','htmlspecialchars')则在首页显示并截取数据字符串时,采用

{$m.content|htmlspecialchars_decode|strip_tags|cut_str=###,200,0}

其中,先把以过html转义过的数据“<”恢复成如“<a>”这样的html标签,再用strip_tags函数把所有的html数据都去除后再截取。

包括其中的javascript代码都不会显示,也不会运行。

在详细页中使用{$news.content|htmlspecialchars_decode=###}

则在首页截取后显示的是有alert()代码,但不会显示其前面的<script></script>样的字符,同时在详细页中不会显示<script></script>

以及其中间的所有代码。其他html标签正常输出转换。

 

 

2、在接收数据时采用I('content')的形式,则在首页显示并截取数据字符串时,采用

{$m.content|strip_tags|cut_str=###,200,0}

其中,先把直接含html标签的数据利用strip_tags函数进行去除后,再截取字符串输出就可以了。

在详细页中使用{$news.content|htmlspecialchars_decode=###},则在首页截取后显示的是有alert()代码,并且还会有其前面的<script></script>样的字符,

在详细页中,这个会显示javascript所有完整代码,但不会执行。

 

3、在接收数据时采用I('content','','htmlspecialchars')的形式,则在首页显示并截取数据字符串时采用

{$m.content|htmlspecialchars_decode|strip_tags|cut_str=###,200,0}

在详细显示页时使用{$news.content}显示

则首页截取的字符串正常,详细页中的数据显示也是正常的,完整的javascript代码会显示,但不会执行。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
摘要 2 摘要 根据大多数小型企业的网站建设需求分析可知,企业网站前后台主要功能都是大同小 异的。这说明大多数小型企业的网站建设核心基本上是一致的。在当今瞬机万变的市场环 境,快速高效开发是解决问题的关键。对于网站设计者来说,面对大同小异的网站建设需 求,这无非就是设计一个适合大多数小型企业网站建设模板以及企业信息管理的数据库。 在快速高效开发方面, MVC 模式开发可提高开发效率与质量,而 ThinkPHP 框架秉承了 LAMP 架构的优势,严格遵循 MVC 设计模式,使用 RBAC 权限机制,具有轻量级、扩展性强、等优势, 它正符合以上的开发特点。 通过对小型企业的网站建设需要和面向 WEB 开发语言的研究,本文主研发了一个面向 小型企业的网站通用模板。为广大小型网站用户提供了优秀的、全方位的企业网站。 因此,结合 ThinkPHP 框架与 MySQL 数据库的开发模式,建立一个面向小型企业的网站 通用模板,从而促使企业网站在开发技术上更快速与高效,也解决了小型企业在业务更新、 企业宣传、推广成本和推广设计技术上存在的难题。 关键字:ThinkPHP 框架,MVC 设计模式,RBAC 权限,小型企业网站通用模板 目录 3 Abstract According to the majority of the small and medium enterprise website construction demand analysis, the main function of the enterprise website before and after is pretty much the same. This shows that most of the small and medium-sized enterprise website construction core is basically consistent. In today's instantaneous change of market environment, fast and efficient development is the key to solve the problem. For web designers, in the face of the same website construction requirements, this is to design a website construction template which is suitable for most small and medium-sized enterprise, and enterprise information management database. In the aspect of rapid and efficient development, the MVC pattern development can improve the development efficiency and quality, while the ThinkPHP framework inherits the advantages of the LAMP architecture, strictly follows the MVC design pattern, using RBAC access mechanism, has the advantages such as lightweight, strong expansibility, etc. It is conform to the above characteristics of development. Through the study of the website construction to the needs of small and medium-sized enterprises and WEB oriented development language, I developed a site generic template for small and medium enterprise. This template uses Thinkphp + MYSQL as a technology foundation for development. Using MVC development mode, modular development mode as the function forms of development. This framework is easy t

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值