searching tags and replace

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
kusal
Forum Newbie
Posts: 14
Joined: Mon Oct 22, 2007 12:12 pm

searching tags and replace

Post 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
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: searching tags and replace

Post 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);
Post Reply