PHP正则表达式将新行限制为最多两行

I'm using this but it's replacing single occurances of a new line with <br/><br/>

function nl2br2($string){
    $string = preg_replace('/(
){2,}/', '<br/><br/>', $string);
    //$string = preg_replace('/[
]/', '<br/>', $string);
    return $string;
}

It happens with the first pattern.

Well, I suspect that perhaps your input may not be '/r/n' but only ' '. In this case you should make your regex to detect that like this: '/(? ){2,}/'.

So your code might be:

function nl2br2($string){
    $string = preg_replace('/(?
){2,}/', '<br/><br/>', $string);
    return $string;
}

Hopes this helps.

with the assistance of NawaMan i made my code this

function nl2br2($string){
    $string = preg_replace('/(?
){2,}/', '<br/><br/>', $string);
    $string = preg_replace('/(?
)+/', '<br/>', $string);
    return $string;
}

:) thanks