<div class="apple">
<a href="..." > ... </a>
<div class="boy">
(some content here)
</div>
<div class="cat">
<b>Text One.</b> <br> <i>Text Two.</i>
</div>
<div class="dog">
<b>Text One.</b> <br> <i>Text Two.</i>
</div>
</div>
.
. (and there are couple more structure with cat class inside but not necessarily under the class apple)
.
<div class="zoo">
.
<div class="cat">
<b>Text One.</b> <br> <i>Text Two.</i>
</div>
.
</div>
.
.
.
I am working with PHP. I want to know that how to select exactly "Text One." only from the div class="cat" the under div class="apple" out of the html (but not from any other).
Currnetly I am doing something like this:
$html=file_get_contents('xxx.html');
$a=preg_match_all("/\<div class\=\"apple\"(.*)\<div class\=\"cat\"\>(.*)<\/b\>/s",$html,$b);
foreach ($b[1] as $value) {
echo strip_tags("$value");
}
I just found it online, it may be possible but not be the best choice to due with the situation.
Many irrelevant content were also selected (i got everything within the last tag and more content than i want in )
please suggest me the appropriate regular expression or a better way to solve.