我有這樣的HTML代碼寫更好的preg_replace
<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
第一個問題,我不知道如何編寫模式來獲得班級顯示:無 第二個問題,我的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);
http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-標籤#1732454 –