zoukankan      html  css  js  c++  java
  • html 实体转换为字符:转换 UEditor 编辑器 ( 在 ThinkPHP 3.2.2 中 ) 保存的数据

    在 ThinkPHP 3.2.2 中使用 UEditor 编辑器保存文章内容时,数据库中保存的数据都被转义成实体,例如:<p><strong><span style="font-family: 微软雅黑, 'Microsoft YaHei'; color: rgb(192, 0, 0);"><em><span style="font-family: 微软雅黑, 'Microsoft YaHei'; text-decoration: underline;">fonts</span></em></span></strong></p>

    如图:

    实际上存入的数据是:

    那么如果准备在后台编辑已经保存过的数据时,如果不做相应的处理,编辑框内则会出现:

    只需要在取出数据时进行相应的处理:

    $con['content'] = htmlspecialchars_decode(html_entity_decode($con['content']));

    则编辑框内能正确显示保存的数据:

    附:

    html_entity_decode():把 HTML 实体转换为字符,是 htmlentities() 的反函数。

    htmlspecialchars_decode(): 把一些预定义的 HTML 实体转换为字符。

    如果是 <textarea> 未经处理存入数据库的 html 代码,取出时只需要使用 htmlspecialchars_decode() 函数。

  • 相关阅读:
    F. The Treasure of The Segments
    D. Zigzags
    C. Binary String Reconstruction
    B. RPG Protagonist
    中国计量大学同步赛补题
    Teacher Ma专场补题
    2020ICPC上海站总结&补题
    华东202011月赛补题
    算法学习之旅——树状数组
    迷宫
  • 原文地址:https://www.cnblogs.com/dee0912/p/4155036.html
Copyright © 2011-2022 走看看