Possible Duplicate:
How to parse and process HTML with PHP?
$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>';
I have the above html as a string in a php variable as shown. I need to get the text of the anchor tag and the link i.e. href of the anchor tag. I need to do the processing in php. Can anyone please help?
Use DomDocument to parse the String and then use getElementsByTagName function to retrieve all the
aelements. Then you can just iterate over them using foreach and retrieve the data you want. Check out DomElement for a list of possible properties and methods.