Possible Duplicate:
RegEx match open tags except XHTML self-contained tags
I have some span, the relation like this:
<span class="aa">word1</span><span class="bb">word2</span>...<!-- otehr html elements -->
<span class="aa">word3</span><span class="bb">word4</span>
how to use REGX, put each span.aa
into the next span.bb
?
<span class="bb"><span class="aa">word1</span>word2</span>...<!-- otehr html elements -->
<span class="bb"><span class="aa">word3</span>word4</span>
Here is something I do with simple_html_dom.php
, but this just do whatever one group of spans, and I have many span like this situation.(there also have other html elements between spans.
<?php
require 'simple_html_dom.php';
$html ='<span class="aa">word1</span><span class="bb">word2</span>';
$newhtml = str_get_html($html);
$span = $newhtml->find('span', 0);
$span1 = $newhtml->find('span', 1);
echo str_replace('class="bb">','class="bb">'.$span,$span1);
?>