I have a string of HTML where some inherited div
present and I need to extract only the top level div, for example-
$html= '<div class="test">
<div>
<div>Some text 1</div>
<div>Image content 2</div>
</div>
<div>
<div>Some text 2</div>
<div>Image content 2</div>
</div>
....
</div>';
$regex ='/<divsclass=["']test["']>.*?</div>/is';
preg_match($regex, $html, $matches);
But the real problem is the result shows me only the first Some text 1</div>
, Please help me to figure out where I made the mistakes?
I need to grab the entire class test
'div' as a result matches.
<div>
<div>Some text 1</div>
<div>Image content 2</div>
</div>
<div>
<div>Some text 2</div>
<div>Image content 2</div>
</div>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…