I want divide these html as serval several part. One <h2> or <h3> with some <p> and <span> as one part. I tried explode array('<h2>','<h3>'), but it caused Warning. the explode not support multi choose.
So how to do it perfectly? Thanks.
$text=<<<EOT
<h2>title1</h2>
<p>something</p>
<span>something</span>
<h3>title2</h3>
<p>something</p>
<p>something</p>
<p>something</p>
<h2>title3</h2>
<span>something</span>
<h2>title4</h2>
<span>something</span>
<p>something</p>
<p>something</p>
EOT;
foreach ($text as $result) {
$arr = explode(array('<h2>','<h3>'),$result);
reset($arr);
foreach($arr as $line){
echo $line.'<hr />';
}
}
Warning: Invalid argument supplied for foreach() on line 23;
My expected output is:
<h2>title1</h2>
<p>something</p>
<span>something</span>
___________________________
<h3>title2</h3>
<p>something</p>
<p>something</p>
<p>something</p>
___________________________
<h2>title3</h2>
<span>something</span>
___________________________
<h2>title4</h2>
<span>something</span>
<p>something</p>
<p>something</p>
___________________________