PHP and preg_replace - How to match htmls tags?

I have developed a regex that works fine in Regex Coach (a freeware regex testing program), but it doesn't work when I try it in preg_replace with PHP.

This is my regex to match opening and closing html tag: "linkhtml"
</?linkhtml[^>]*/?>

Open in new window

and my PHP:
$str = preg_replace('/</?linkhtml[^>]*/?>/', '', $str);

Open in new window

When I run this in the php debugger I get the error:
Unknown modifier '?'
Any idea what I'm doing wrong?
agrarian3Asked:
Who is Participating?
 
Lukasz ChmielewskiConnect With a Mentor Commented:
You need to escape the  "/"
$str = preg_replace('/<\/?linkhtml[^>]*\/?>/', '', $str);
0
 
agrarian3Author Commented:
Thanks, that did it!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.