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

Rebecca O'Connell rloconne at unity.ncsu.edu
Mon Dec 1 10:37:48 CST 2003


Rob:

I have some experience with RegExps and no experience with PHP, but from
what I can see, the problem might be the / character. This character is used
to denote the beginning of a regexp (at least it is in JavaScript) and might
need a \ in front of it to make it a literal character. Also, I've never
heard of using # to indicate a number (the form I use is \d). However, since
it seems to be working for you, maybe you can use it in PHP.

HTH,
Rebecca

On 12/1/03 9:45 AM, "Rob Schumann" <robs at rs-tc.com> wrote:

> 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