doulei2100 2015-06-26 01:37
浏览 158

jQuery只转义某些html实体

I have a little profile system with mentions in place

The 'content' value in my Posts table is stored as:

<a href="/profile/Alice">Alice</a> Alice, you there? &lt;strong&gt;lol&lt;/strong&gt;
  • the a href Profile link is generated by my system (I replace all mentions with a html link to the profile)
  • the <strong>lol</strong> are user-defined HTML that I do not wish to display (I use htmlentities() on all user-posts so their html input becomes that)

However, the end-result is everything being shown as HTML (I display them using json and jquery). How can I make it such that it only shows the in HTML (for my mention links), but not all the user-specified ones? (i.e. <strong>)

I want the post to display the mentions in hyper link, but at the same time, I do not want all user entered html to be displayed as html.

I use jQuery append to display my posts.

Thanks!

  • 写回答

2条回答 默认 最新

  • doutui6644 2015-06-26 01:40
    关注
    $str = '<a href="/profile/Alice">Alice</a> Alice, you there? &lt;strong&gt;lol&lt;/strong&gt;';
    $str = html_entity_decode($str);
    echo $str;
    exit;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?