views:

160

answers:

1

I have a string like this:

<span style="font-weight: bold;">Foo</span>

I want to use PHP to make it

<strong>Foo</strong>

…without affecting other spans.

How can I do this?

+1  A: 
$text='<span style="font-weight: bold;">Foo</span>';
$text=preg_replace( '/<span style="font-weight: bold;">(.*?)<\/span>/', '<strong>$1</strong>',$text);

Note: only work for your example.

S.Mark
Thanks! Works like a charm.
anon
@anon Wait until you hit a `span style="font-weight:bold;"` (notice the lack of space between : and bold) or `span style="color:red; font-weight: bold;"` or any other perfectly valid html.
Amarghosh