Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 494
  • Last Modified:

preg_replace() Unknown modifier 'h'

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
hankknight
Asked:
hankknight
1 Solution
 
VoteyDiscipleCommented:
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
 
dasmaerCommented:
or just escape any / in your code, so you'd have: '/<h[1-9]>.*?<\/h[1-9]>/'
0

Featured Post

Independent Software Vendors: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now