jamesmiller Posted September 28, 2011 Share Posted September 28, 2011 Hey guys, im currently writing a crawler to grab all text withing two html tags : <h2 class="posttitle"> <a class="entry-title" title="ANYTHING here" rel="bookmark" href="http://ANYURL">ANYTHING here</a> </h2> and i want to grab all of these so a preg_match_all for everything between <h2 class="posttitle"> and </h2> Thank you for any help Link to comment https://forums.phpfreaks.com/topic/248026-html-tag-grabbing/ Share on other sites More sharing options...
AyKay47 Posted September 28, 2011 Share Posted September 28, 2011 <?php $string = "<h2 class='posttitle'> <a class='entry-title' title='ANYTHING here' rel='bookmark' href='http://ANYURL'>ANYTHING here</a> </h2> "; $pattern = "~<h2 .*>(.*)</h2>~is"; preg_match($pattern,$string,$matches); print_r($matches); ?> Link to comment https://forums.phpfreaks.com/topic/248026-html-tag-grabbing/#findComment-1273545 Share on other sites More sharing options...
jamesmiller Posted September 28, 2011 Author Share Posted September 28, 2011 AyKay47, Thank you worked perfectly Link to comment https://forums.phpfreaks.com/topic/248026-html-tag-grabbing/#findComment-1273547 Share on other sites More sharing options...
.josh Posted September 28, 2011 Share Posted September 28, 2011 fyi, DOM is a better method. Link to comment https://forums.phpfreaks.com/topic/248026-html-tag-grabbing/#findComment-1273569 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.