[thelist] Regex problems stripping </p>'s

Rob Schumann roblgs at cscoms.com
Mon Dec 1 08:45:14 CST 2003


Hi,

Could someone more proficient with regex than I am point me to what is wrong with this.

I'm trying to strip the paragraph tags from markup like this (it results from  inserting paragraph tags for line breaks)

<p><h3>Some text</h3></p>

into

<h3>Some text</h3>

There are other instances with different level head tags. The first of these ereg replaces works fine, so I assume that the regex for PARA_HEAD is OK.

That for the HEAD_PARA however doesn't work and I end up with markup like this

<h3>Some text</h3></p>

I'm using the following php...

define ('PARA_HEAD', "<[p|P]>(<[h|H]#>)" );
define ('HEAD_PARA', "(</[h|H]#>)</[p|P]>" );
$newtext = ereg_replace (PARA_HEAD, "\\1", $newtext);
$newtext = ereg_replace (HEAD_PARA, "\\1", $newtext);

If however I define HEAD_PARA to be "(</h3>)</p>" and thus specific to /h3 tags, then it does work. It's got to be something daft, I just can't see what...

TIA

Rob

Rob Schumann
Managing Director                   M: +66 (0)1 860 4533
RS-Tech Consulting Co., Ltd.        T: +66 (0)2 516 2991
70/592 Moo 3 Krisdanakorn 19,       F: +66 (0)2 516 4025
Klong Nung, Klong Luang,            E:    robs at rs-tc.com
Pathum Thani 12120,                    roblgs at cscoms.com
Thailand                        W: http://www.rs-tc.com/


More information about the thelist mailing list