Here is what I need to be able to do:
I need to match the following tag:
<SPAN style="TEXT-DECORATION: underline">text sample</SPAN>
I need to replace the span with an html3 compliant tag, but keep the text in between. The final tag should look like this after replacement:
<u>text sample</u>
I'm just not good with regular expressions and can't seem to come up with the answer.
Thank you in advance.
Regular expressions are not designed for tag manipulation.
If you have any form of nesting going on, it gets messy.
However, given the very simple example provided you could perhaps do this:
$MyString = preg_replace
( '/(?si)<SPAN\s+style\s*=\s*"TEXT-DECORATION:\s*underline;?"\s*>(.*?)<\/SPAN>/'
, '<u>$1</u>'
, $MyString
);
But this is flawed in many ways, and you are much better off using a tool designed for manipulating tags instead.
Have a look at DOMDocument->loadHTML() and related functions.