Solved

preg_replace() Unknown modifier 'h'

Posted on 2006-11-30
2
451 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
ID: 18046373
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
ID: 18046409
or just escape any / in your code, so you'd have: '/<h[1-9]>.*?<\/h[1-9]>/'
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

785 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