dongxi1943 2015-03-10 20:26
浏览 34

如何在包含实体的字符串上使用PHP htmlentities

I have a problem. In my database I allow users to submit post titles through an input containing html entities and plaintext. As per what I have read, I use mysqli_real_escape_string to escape their post before adding it to the database, and then use htmlentities when the html is being output onto a page. However if the user posts something like

 <div>( ͡° ͜ʖ ͡°)</div>

it gets mysqli escaped and stored in the database as

"<div>( &#865;° &#860;&#662; &#865;°)</div>"

if I then use htmlentities on this string when outputting, it will return nothing. This must be something to do with the html entities already in the string, because if I test

<div>plaintext</div>

it works fine. How can I escape the html entities such as < and > within a string already containing encoded entities?

  • 写回答

2条回答 默认 最新

  • dongqiang4986 2015-03-10 20:33
    关注

    The purpose of htmlentities is to convert special characters into browser-renderable strings. Browsers will render the converted characters, so no re-conversion through htmlentities is required.

    (POST)->htmlentities->mysqli_real_escape_string->(stored)->(SELECT)->(display)

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动