I want to fetch particular data from a page like title of the product from html tags
Below is my div code from website -
<div class="pdct-inf">
<h2 class="h6" style="min-height:38px;height:38px;">
<a id="ctl00_cphMain_rPdctG_ctl01_hTitle" href="/whirlpool-whirlpool-direct-drive-285753a-ap3963893.html">Whirlpool Direct Drive Washer Mot...</a></h2><div class="startext">
<div itemprop="reviewRating" itemscope="" itemtype="http://schema.org/Rating" style="cursor:pointer; float:left; text-align:right;" class="page-style-stars-web-sm rating-5"></div>
<meta itemprop="worstRating" content="1"><meta itemprop="bestRating" content="5"><meta itemprop="ratingValue" content="5"> (<a href="/whirlpool-whirlpool-direct-drive-285753a-ap3963893.html#diy">434</a>)
</div>
</div>
I want to fetch this text Whirlpool Direct Drive Washer Mot...
in between <a>
Below is my php code -
<?php
$html = file_get_contents("http://www.programminghelp.com/");
preg_match_all(
'/<h2><a href="(.*?)" rel="bookmark" title=".*?">(.*?)<\/a><\/h2>/s',
$html,
$posts, // will contain the article data
PREG_SET_ORDER // formats data into an array of posts
);
foreach ($posts as $post) {
$link = $post[1];
$title = $post[2];
echo $title . "\n";
}
echo "<p>" . count($posts) . " product found</p>\n";
?>
I need help to write regexp for above div content.
preg_match_all(
'/<h2><a href="(.*?)" rel="bookmark" title=".*?">(.*?)<\/a><\/h2>/s',