可能重复:
如何使用 PHP 解析和处理 HTML?
$strHTML = '<div>
<h2 class="entry-title">
<a rel="bookmark" title="Permalink to BSR Fuels Report; Rezidor Hotels to Reduce Energy; Germany Caps Subsidies – 3BL Media Energy Minute" href="http://www.caelusgreenroom.com/2012/10/17/bsr-fuels-report-rezidor-hotels-to-reduce-energy-germany-caps-subsidies-3bl-media-energy-minute/">BSR Fuels Report; Rezidor Hotels to Reduce Energy; Germany Caps Subsidies – 3BL Media Energy Minute</a>
</h2>
<h2 class="entry-title">
<a rel="bookmark" title="Permalink to Small Business Healthcare Costs to Decrease; EU Pharma Guidelines – 3BL Media" href="http://www.caelusgreenroom.com/2012/10/17/small-business-healthcare-costs-to-decrease-eu-pharma-guidelines-3bl-media/">Small Business Healthcare Costs to Decrease; EU Pharma Guidelines – 3BL Media</a>
</h2>
</div>';
如图所示,我将上述 html 作为 php 变量中的字符串。我需要获取锚标签的文本和锚标签的链接,即href。我需要在 php 中进行处理。有人可以帮忙吗?