如何删除< br/>标签以及更多来自字符串的内容? [英] How to remove <br /> tags and more from a string?
问题描述
我需要去除所有<br />
和所有'quotes'("
)和所有'ands'(&
)并仅用空格替换...
I need to strip all <br />
and all 'quotes' ("
) and all 'ands' (&
) and replace them with a space only ...
我该怎么做? (在PHP中)
How can I do this? (in PHP)
我已经为<br />
尝试过此操作:
I have tried this for the <br />
:
$description = preg_replace('<br />', '', $description);
但是它返回了<>
来代替每个<br />
...
But it returned <>
in place of every <br />
...
谢谢
推荐答案
要操纵HTML,通常最好使用DOM感知工具代替纯文本操纵工具(例如,想想像enounter这样的变体会发生什么情况? <br/>
,<br />
具有多个空格,甚至甚至使用了<br>
或<BR/>
,尽管这些空格完全是非法的).在此处查看示例: http://sourceforge.net/projects/simplehtmldom/
To manipulate HTML it is generally a good idea to use a DOM aware tool instead of plain text manipulation tools (think for example what will happen if you enounter variants like <br/>
, <br />
with more than one space, or even <br>
or <BR/>
, which altough illegal are sometimes used). See for example here: http://sourceforge.net/projects/simplehtmldom/
这篇关于如何删除< br/>标签以及更多来自字符串的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!