• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 384
  • 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
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.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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