windows - PHP regex to limit new lines to a maxmium of two -
I'm using it, but it's a new line's single code to & lt; Br / & gt; & Lt; Br / & gt;
function nl2br2 ($ string) {$ string = preg_replace ('/ (\ r \ n) {2,} /', '
br / & gt; & Lt; br / & gt; ', $ string); // $ string = preg_replace ('/ [\ r \ n] /', '
', $ string); Return $ string; }
It happens with the first pattern.
OK, I suspect that your input may not be '/ r / n', but Only '\ n'. In this case, you should find out your regex that: '/ (\ r? \ N) {2,} /'
Your code may be:
function nl2br2 ($ string) {$ string = preg_replace ('/ (\ r? \ N) {2,} / ','
Return $ string; }
It helps.
Comments
Post a Comment