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

WBOY
Release: 2016-06-24 12:02:35
Original
1359 people have browsed it

正责表达式如何过滤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);
Copy after login
Copy after login

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

$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));
Copy after login
Copy after login

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);
Copy after login
Copy after login

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

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

$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));
Copy after login
Copy after login

谢谢回复哦,不过我要在jsp里面写哦,不是hph里面
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template