Jump to content

HTML tag grabbing


jamesmiller

Recommended Posts

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

<?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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.