PHP regex - find and replace

Posted by jay on Stack Overflow See other posts from Stack Overflow or by jay
Published on 2010-04-07T16:16:08Z Indexed on 2010/04/07 16:23 UTC
Read the original article Hit count: 338

Filed under:
|

Hi,

I am trying to do this regex match and replace but not able to do it.

Example

<SPAN class="one">first content here</SPAN>
<SPAN class="two">second content here </SPAN>
<SPAN class="three">one; two; three; and more.</span>
<SPAN class="four">more content here.</span>

I want to find each set of the span tags and replace with something like this

Find

<SPAN class="one">first content here</SPAN>

Change to

<one>first content here</one>

same way the the rest of the span tags.

class="one", class="two" and so on are the only key identifier which I use in the regex match expression. So if I find a span tag with these class then I want to do the replace. My main issue is that I am not able to find the occurrence of first closing tag so what it does is it finds from the start to end which is of no use. So far I have been trying to do this using notepad++ but just found that it has its limitations so any php help would be appreciated.

regards

© Stack Overflow or respective owner

Related posts about php

Related posts about regex