• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 382
  • Last Modified:

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?
0
agrarian3
Asked:
agrarian3
1 Solution
 
Lukasz ChmielewskiCommented:
You need to escape the  "/"
$str = preg_replace('/<\/?linkhtml[^>]*\/?>/', '', $str);
0
 
agrarian3Author Commented:
Thanks, that did it!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now