我有这个字符串(在 html 中):
<div class="sliderImg">
<img width="1000" height="666" src="/consultants/images/projectbank/simansi-vaseon.jpg">
<img width="1000" height="666" src="/consultants/images/projectbank/oloklirosi-parkou.jpg">
<img width="1000" height="666" src="/consultants/images/projectbank/inverters.jpg">
</div>
<div class="projectProperties">
<ul>
<li class="projCategory">Project category: <span class="text">Energy</span></li>
<li class="projEntity">Entity: <span class="text">Bright Wind and Solar</span></li>
<li class="projRegion">Region: <span class="text">Southwest</span></li>
<li class="projYear">Year: <span class="text">2010</span></li>
<li class="projStatus">Status: <span class="text">Complete</span></li>
<li class="projContribution">Contribution: <span class="text">Study and construction</span></li>
</ul>
</div>
<div class="projectDesc">
<p>Duis lectus arcu, auctor scelerisque diam a, hendrerit sagittis risus. Donec eget urna metus. Nulla sapien felis, vehicula vel convallis et, facilisis a nunc. Donec ac diam ut nisl rutrum convallis. Phasellus pellentesque turpis sit nullam.</p>
</div>
我想只保留最后一个div
classprojectDesc
,使用preg_replace
and regex
。
<div class="projectDesc">
<p>Duis lectus arcu, auctor scelerisque diam a, hendrerit sagittis risus. Donec eget urna metus. Nulla sapien felis, vehicula vel convallis et, facilisis a nunc. Donec ac diam ut nisl rutrum convallis. Phasellus pellentesque turpis sit nullam.</p>
</div>
我在 SO 中搜索了许多帖子,但找不到与regex
我应该使用哪种相关的任何内容。你能否指出我正确的方向,如果这甚至可能只使用preg_replace
and regex
?