This is a discussion on How do I remove extra line breaks beyond two? within the PHP Language forums, part of the PHP Programming Forums category; Hello - What is the correct expression to remove any extra line breaks beyond two in a string? Sincerely, Jim...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
On 25 Feb 2005 15:25:17 -0800, revjjjames@hotmail.com wrote:
>What is the correct expression to remove any extra line breaks beyond >two in a string? There any may ways but I'd probably use something like: $string = preg_replace('/(?<=\n)(\n?)\n*/s', "$1", $string); -- Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk> <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool |
|
|||
|
<revjjjames@hotmail.com> wrote in message
news:1109373917.583770.16760@g14g2000cwa.googlegro ups.com... > Hello - > > What is the correct expression to remove any extra line breaks beyond > two in a string? > > Sincerely, > > Jim > The simpliest way is to replace linebreaks of three or more with two. Ugly regexp: preg_replace('/(?:(?:\r\n)|\r|\n){3,}/', "\n\n", $str); |