Preg_replace/str_replace() 用于将 `<` 和 `>` 实例分别更改为 `<` 和 `>` [英] Preg_replace/str_replace() for changing `&lt;` and `&gt;` instances to `<` and `>` respectively
问题描述
我们的一个页面使用以下代码从数据库表中提取内容:
One of our pages pulls content from a database table using the following code:
<?php echo $project['description'];?>
我需要的是将所有 <
和 >
实例替换为 <
和 >
分别.你能帮忙修改上面的代码以包含一个 preg_replace
语句(或 str_replace()
)?
What I need is for all <
and >
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("<","<",str_replace(">",">",$project['description'])); ?>
并且 preg_replace 应该是这样的:
And preg_replace should look like this:
<?php echo preg_replace(<,"<",preg_replace(>,">",$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() 用于将 `<` 和 `>` 实例分别更改为 `<` 和 `>`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!