Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace <span style="font-weight: bold;">foo</span> by <strong>foo</strong> using PHP and regex?

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?

like image 312
anon Avatar asked Dec 28 '22 18:12

anon


1 Answers

$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.

like image 195
YOU Avatar answered Jan 12 '23 00:01

YOU