Page 1 of 1

searching tags and replace

Posted: Mon Dec 22, 2008 6:03 am
by kusal
I want to find this pattern in a string <span style="text-decoration: underline;">Text here</span> and change the tags to <u>kusal</u>

How can I use preg_replace to do this?

Thanks

Re: searching tags and replace

Posted: Mon Dec 22, 2008 7:56 am
by prometheuzz
Like this:

Code: Select all

$text = '<span style="text-decoration: underline;">Text here</span>';
echo preg_replace('@<span\s*style="text-decoration:\s*underline;">(?:(?!</span>).)*</span>@i', '<u>kusal</u>', $text);