[PHP] Removing Empty Lines from Text??

2002-06-24 Thread Jason Caldwell

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




Re: [PHP] Removing Empty Lines from Text??

2002-06-24 Thread Justin French

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




Re: [PHP] Removing Empty Lines from Text??

2002-06-24 Thread Jason Wong

On Monday 24 June 2002 16:56, Justin French wrote:
 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.

To add my tuppence's worth, I would search for and remove any white spaces 
between \n's as well. Something like replace \n\s*\n with \n.

-- 
Jason Wong - Gremlins Associates - www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
It's a .88 magnum -- it goes through schools.
-- Danny Vermin
*/


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