Home >Web Front-end >HTML Tutorial >How to filter html with positive expression and take out the text part in the middle_html/css_WEB-ITnose

How to filter html with positive expression and take out the text part in the middle_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:02:351384browse

正责表达式如何过滤html,取出中间的文字部分:如下面,如何使用正责表达式取出“我们去哪”
<span style="color:#ff3333;font-size:medium;"><strong>我们去哪</strong></span>


回复讨论(解决方案)

var str = '&lt;span style="color:#ff3333;font-size:medium;"&gt;&lt;strong&gt;我们去哪&lt;/strong&gt;&lt;/span&gt;';var reg = /\<[^\>]+\>/g;str = str.replace(/\&lt;?/g,"<").replace(/\&gt;?/g,">").replace(reg,"");console.log(str);

用正则占用资源,你这种情况可以不用正则来做。

$content = '&lt;span style="color:#ff3333;font-size:medium;"&gt;&lt;strong&gt;我们去哪&lt;/strong&gt;&lt;/span&gt;';echo strip_tags(htmlspecialchars_decode($content));

var str = '&lt;span style="color:#ff3333;font-size:medium;"&gt;&lt;strong&gt;我们去哪&lt;/strong&gt;&lt;/span&gt;';var reg = /\<[^\>]+\>/g;str = str.replace(/\&lt;?/g,"<").replace(/\&gt;?/g,">").replace(reg,"");console.log(str);

谢谢哦,用你的办法解决了

用正则占用资源,你这种情况可以不用正则来做。

$content = '&lt;span style="color:#ff3333;font-size:medium;"&gt;&lt;strong&gt;我们去哪&lt;/strong&gt;&lt;/span&gt;';echo strip_tags(htmlspecialchars_decode($content));

谢谢回复哦,不过我要在jsp里面写哦,不是hph里面
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn