Solved

PHP and preg_replace - How to match htmls tags?

Posted on 2013-01-15
2
364 Views
Last Modified: 2013-01-15
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
Comment
Question by:agrarian3
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 500 total points
ID: 38779420
You need to escape the  "/"
$str = preg_replace('/<\/?linkhtml[^>]*\/?>/', '', $str);
0
 

Author Closing Comment

by:agrarian3
ID: 38779434
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question