-2

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);
?>
Community
  • 1
  • 1
fish man
  • 2,666
  • 21
  • 54
  • 94
  • 1
    http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags – Alex Howansky Oct 19 '11 at 19:08
  • @Alex Howansky, too many span make me headeache. And now I studing jquery, my brain full of `each` `next` selection, so ask for a quickly help. – fish man Oct 19 '11 at 19:15
  • 1
    @Alex please find a better duplicate than the old (and wrong) slapdown "you cant" answer. – Gordon Nov 11 '11 at 10:44

1 Answers1

0

If this is the only thing you need to do you could, find all <span class="bb">, replace them with an empty string, then find all <span class="aa"> and replace them with <span class="bb"><span class="aa">

Ben
  • 13,297
  • 4
  • 47
  • 68
  • thanks for suggestion, I also think this way, but how to? I still not find a work way both `regex` or `simple dom`, it is too dificult for me, need a help. – fish man Oct 20 '11 at 18:38