如何仅删除字符串中的html标签? [英] How to remove only html tags in a string?
本文介绍了如何仅删除字符串中的html标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经写了删除HTML标签的代码,但是它也删除了a<b
类型的字符串.我希望它不要删除2<3
或a<b
之类的字符串.
I have written code for removing HTML tags, but it is also removing a<b
type of strings. I want it to not to remove strings like 2<3
or a<b
.
$term="a<b";
echo "Text is--->".preg_replace('/(?:<|<).+?(?:>|>)/', '', $term);
如何在不删除LT或GT的情况下删除字符串中的html标签?
How do I remove html tags in a string, without removing LT or GT?
推荐答案
对不起,我的验证不够.
Sorry I had not validate enough.
我已经在下面检查了php5-cli表达式.
I have checked php5-cli expression below.
(?:<|<)\/?([a-zA-Z]+) *[^<\/]*?(?:>|>)
PHP代码可用:
#!/usr/bin/php
<?php
$str = "<html></html>
a<b 1<2 3>1
<body>1>2</body>
<style file=\"'googe'\" alt=\"google\">hello world</style>
<have a good efghijknopqweryuip[]asdfgghjkzxcv bnm,.me>hello world<> google com</s>
<a se=\"font: googe;\">abcde</a>";
echo "text--->".preg_replace('/(?:<|<)\/?([a-zA-Z]+) *[^<\/]*?(?:>|>)/', '', $str)."\n";
?>
结果:
text--->
a<b 1<2 3>1
1>2
hello world
hello world<> google com
abcde
这篇关于如何仅删除字符串中的html标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文