Well, in short, you want to replace \n\n\n or \n\n\n\n with \n\n.

This can be done cleaverly with a regexp (not my expertise at all, but you
want to replace 3 or more occurences of \n in a row with \n\n.

Otherwise, a simple str_replace() will do it an okay job.

something like:

<?
$str = "something\n\nwith\n\ntoo\n\n\nmany\n\n\n\nline\nbreaks";
$str = str_replace('\n\n\n','\n\n',$str) // change three enters to two
$str = str_replace('\n\n\n\n','\n\n',$str) // change four enters to two
?>

Untested of course.

Like I said, a regexp would be better here.


Justin French




on 24/06/02 6:51 PM, Jason Caldwell ([EMAIL PROTECTED]) wrote:

> Is there an elegant way to remove excess blank lines from my form data?
> 
> For example;  if someone enters the following text and then press' the
> Submit button:
> 
> ----
> This is a some text
> 
> 
> This is more text, and yet even more....
> ----
> 
> What I want to do is remove the excess white space and make it look like
> this?
> 
> ----
> This is a some text
> 
> This is more text, and yet even more....
> ----
> 
> My users may press <enter> too many times and I want to ensure clean text
> and formatting.
> 
> Thanks.
> Jason
> 
> 
> 
> 


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

Reply via email to