Ok, let me try to refine this as the big picture.  User enters something into
a form.

We take that form value and convert newlines into <br /> though nl2br.

Then, I want the limit the number of consecutive <br />'s a user can enter,
to avoid abuse via a person just holding down enter for a while.

$message = nl2br($message);
$message = preg_replace("/\n/", "", $message);

while (stristr($message, '<br /><br /><br />')) {
   $message = str_replace('<br /><br /><br />', '<br /><br />', $message);
}

For some reason, nl2br leaves a newline after each <br /> in the actual code.
So, If I type something in like:

Hello


How are you?


The string will contain the value:

Hello<br />
<br />
<br />
<br />
How are you?


it NEEDS to say:

Hello<br /><br /><br /><br />How are you?

I just can't get this to work at all.  I think my head's going to explode, as
I've been trying to get this to work for a few hours now





On Wednesday 27 March 2002 02:53 pm, you wrote:
> This is just an example.  There are some cases where I need the second
> option to be a regular expression, the same way that you can do in Perl
> regex...
>
> On Wednesday 27 March 2002 02:49 pm, you wrote:
> > On Wed, 27 Mar 2002, James Taylor wrote:
> > > I'm trying to do something to the effect of this for a preg_replace
> > > statement:
> > >
> > > $string = "Hello\n\n\n\n\n\n\nHow are you?\n\n\n\n\n\n\n\nHi";
> > > $string = preg_replace("/\n\n/", "/\n/", $string);
> > >
> > >
> > > But, it appears the 'replace' portion of the function doesn't allow for
> > > regex.  How can I do this so that I CAN have the second statement be
> > > regex?
> >
> > I think you just have your syntax messed up. You don't need delimiters
> > around the second argument.
> >
> >   $string = preg_replace("/\n\n/", "\n", $string);
> >
> > miguel


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to