?
Solved

PHP and preg_replace - How to match htmls tags?

Posted on 2013-01-15
2
Medium Priority
?
366 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

771 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