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 Quote 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); ?> Quote 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 Quote 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. Quote Link to comment https://forums.phpfreaks.com/topic/248026-html-tag-grabbing/#findComment-1273569 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.