Forum Moderators: coopster

Message Too Old, No Replies

Preg_replace difficulties

Taking two lines as one?

         

BlueScreen

4:37 pm on Jul 4, 2005 (gmt 0)

10+ Year Member



Hi,

I've been struggling with trying to find a way to remove every occurence in my page when there are 2 or more <br />'s, but not when there is only one

Basically, what I want is to allow all single <br />'s through, but when there are 2 or more <br />'s next to each other, to remove it

I tried using this code

$page = preg_replace('/(<br \/>){2,}/is','',$page);

Which works when there are 2 <br />'s right NEXT to each other, but if the second <br /> is on another line, it doesnt work. I thought the /s was supposed to fix this (take it in as a single line)?

Is there any way I can make it work for when the code goes like this:

<br />
<br />

as well as

<br /><br />

I'd apreciate any help

Thanks

j4mes

4:48 pm on Jul 4, 2005 (gmt 0)

10+ Year Member



/s

You mean \s, right?

\s can be used to match a single white space character, including tabs and newline characters.

bennymack

6:48 pm on Jul 4, 2005 (gmt 0)

10+ Year Member




/m

should treat the input as a multiline value and ignore \n

BlueScreen

8:23 pm on Jul 4, 2005 (gmt 0)

10+ Year Member



Thanks for the replies

j4mes: Are you sure? I've been using it with a / in that direction rather than a \ for all the other regexp and it works. Also, the i tag tag works with it that way?

bennymack, I tried that, but I still get nothing, same as when using /s

The code I tried was

$page = preg_replace('/(<br \/>){2,}/im','test',$page);