Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 537
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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