Solved

preg_replace() Unknown modifier 'h'

Posted on 2006-11-30
2
444 Views
Last Modified: 2008-03-10
Hello,

This gives me an error.

I want to remove ALL <h> tags, and also all words between h tags.

      $sitecontents = preg_replace('/<h[1-9]>.*?</h[1-9]>/', '', $sitecontents);
0
Comment
Question by:hankknight
2 Comments
 
LVL 19

Accepted Solution

by:
VoteyDisciple earned 500 total points
Comment Utility
You're using / to note the beginning and end of the regexp, yet you then have a / inside.  That means PHP thinks "h[1-9]>/" are all modifiers, and not part of the regexp.  How about...

     $sitecontents = preg_replace('|<h[1-9]>.*?</h[1-9]>|', '', $sitecontents);

0
 
LVL 5

Expert Comment

by:dasmaer
Comment Utility
or just escape any / in your code, so you'd have: '/<h[1-9]>.*?<\/h[1-9]>/'
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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.

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now