foo to foo using PHP and regular expression? I have a line like ...">

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

I have a line 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?

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

Note : only works for your example.

+6
source

Source: https://habr.com/ru/post/1743152/


All Articles