I've been dwelling on this for a while.
I have this string (there are more contents before and after the h2 tags):
...<h2 style='line-height: 44px;'><p>Lorem Ipsum</p></h2>...
What regex do I use to remove all the <p> and </p> tags inside those header tags?
I'm trying to do something like this, but the positive lookbehind one is not working:
// for the starting <p> tag
$str = preg_replace('/(?<=<h[1-6]{1}[^>]+>)\s*<p>/i', '', $str);
// for the ending </p> tag
$str = preg_replace('/<\/p>\s*(?=<\/h[1-6]{1}>\s*)/i', '', $str);
This does not take account paragraph tags deep inside the text within the <h2> tag also
[Update]
This is derived from one of PeeHaa's suggested links
// for the starting <p> tag
$str = preg_replace("#(<h[1-6].*?>)<p.*?>#", '$1', $str);
// for the ending </p> tag
$str = preg_replace("#<\/p>(<\/h[1-6]>)#", '$1', $str);