Preg_replace/str_replace() 用于将 `<` 和 `>` 实例分别更改为 `<` 和 `>` [英] Preg_replace/str_replace() for changing `<` and `>` instances to `<` and `>` respectively

查看:28
本文介绍了Preg_replace/str_replace() 用于将 `<` 和 `>` 实例分别更改为 `<` 和 `>`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的一个页面使用以下代码从数据库表中提取内容:

One of our pages pulls content from a database table using the following code:

<?php echo $project['description'];?>

我需要的是将所有 &lt;&gt; 实例替换为 <> 分别.你能帮忙修改上面的代码以包含一个 preg_replace 语句(或 str_replace())?

What I need is for all &lt; and &gt; instances to be replaced with < and > respectively. Can you help modify the above code to include a preg_replace statement (or str_replace())?

推荐答案

<?php echo htmlspecialchars_decode($project['description']); ?>

应该可以满足您的需求.

Should get you what you need.

如果你只是想解码那些,那么:

If you are ONLY looking to decode those, though, then:

<?php echo str_replace("&lt;","<",str_replace("&gt;",">",$project['description'])); ?>

并且 preg_replace 应该是这样的:

And preg_replace should look like this:

<?php echo preg_replace(&lt;,"<",preg_replace(&gt;,">",$project['description'])); ?>

我很确定 & 不是一个特殊字符,但如果它确实给您带来了问题,请在它之前放置一个 \.

I'm pretty sure the & isn't a special character, but if it does cause you issues, put a \ before it.

这篇关于Preg_replace/str_replace() 用于将 `&lt;` 和 `&gt;` 实例分别更改为 `&lt;` 和 `&gt;`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆