ie 替换 <pre>_用HTML实体替换PRE标签中的内容

ie 替换 <pre>

If you have a website that relies heavily on PRE tags, you know the important of converting PRE tag content to their HTML entities. Doing so prevents worlds of possible rendering issues. The following PHP snippet HTML-Entitizes (?) any code within PRE tags:

如果您的网站高度依赖PRE标签,则知道将PRE标签内容转换为其HTML实体的重要性。 这样做可以避免可能出现的渲染问题。 以下PHP代码段HTML会对PRE标签中的任何代码进行HTML修饰(?):


//replaces pre content with html entities
function pre_entities($matches) {
	return str_replace($matches[1],htmlentities($matches[1]),$matches[0]);
}
//to html entities;  assume content is in the "content" variable
$content = preg_replace_callback('/<pre.*?>(.*?)<\/pre>/imsu',pre_entities, $content);


I use this for just about every post I write. You could also stick this in your CMS if you have clients that may have use for PRE tags.

我写的几乎所有帖子都用到它。 如果您的客户可能使用PRE标签,也可以将其粘贴在CMS中。

翻译自: https://davidwalsh.name/php-html-entities

ie 替换 <pre>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值