我有这个 html 代码
<span><style>
.p9Wu{display:none}
.JOz4{display:inline}
.nitJ{display:none}
.pIj0{display:inline}
.AU2Q{display:none}
.vDdS{display:inline}
.THa1{display:none}
.mRy1{display:inline}
</style><span style="display: inline">69</span><span class="JOz4">.</span><span style="display:none">21</span><div style="display:none">21</div><span style="display: inline">65</span><span style="display:none">212</span><span class="AU2Q">212</span><span style="display: inline">.</span><span class="144">46</span><span style="display:none">69</span><span class="237">.</span><span style="display:none">11</span><span class="AU2Q">11</span><div style="display:none">11</div><div style="display:none">36</div><span style="display: inline">60</span><div style="display:none">152</div></span>
在浏览器上查看时,它显示这个 69.65.46.60 我想使用 PHP 去除 html 并只留下文本 69.65.46.60
第一个问题是我不知道如何编写一个模式来获取显示类:none 第二个问题是我的 preg_replace 太长。有人可以帮我缩短它吗?谢谢
这是我的php代码
$html = preg_replace('~<div([^>]*)(class\\s*=\\s*["\']p9Wu["\'])([^>]*)>(.*?)</div>~i', '', $html);
$html = preg_replace('~<div([^>]*)(class\\s*=\\s*["\']nitJ["\'])([^>]*)>(.*?)</div>~i', '', $html);
$html = preg_replace('~<div([^>]*)(class\\s*=\\s*["\']AU2Q["\'])([^>]*)>(.*?)</div>~i', '', $html);
$html = preg_replace('~<div([^>]*)(class\\s*=\\s*["\']THa1["\'])([^>]*)>(.*?)</div>~i', '', $html);
$html = preg_replace('~<span([^>]*)(class\\s*=\\s*["\']p9Wu["\'])([^>]*)>(.*?)</span>~i', '', $html);
$html = preg_replace('~<span([^>]*)(class\\s*=\\s*["\']nitJ["\'])([^>]*)>(.*?)</span>~i', '', $html);
$html = preg_replace('~<span([^>]*)(class\\s*=\\s*["\']AU2Q["\'])([^>]*)>(.*?)</span>~i', '', $html);
$html = preg_replace('~<span([^>]*)(class\\s*=\\s*["\']THa1["\'])([^>]*)>(.*?)</span>~i', '', $html);
$html = preg_replace('~<div([^>]*)(style\\s*=\\s*["\']display:none["\'])([^>]*)>(.*?)</div>~i', '', $html);
$html = preg_replace('~<span([^>]*)(style\\s*=\\s*["\']display:none["\'])([^>]*)>(.*?)</span>~i', '', $html);
$html = preg_replace('@<style[^>]*?>.*?</style>@siu', '', $html);
$html = strip_tags($html);