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);
LVL 16
hankknightAsked:
Who is Participating?
 
VoteyDiscipleConnect With a Mentor Commented:
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
All Courses

From novice to tech pro — start learning today.