php - stripping whitespace and limiting <br> in nl2br() -


here      lot    of      whitespace <br> <br> <br> 3 br's many... want trim 2 <brs> in row 

how can strip out whitespace , limit <br> max of 2 in php? 1 <br> , 2 <br>'s in row acceptable. on 2 gets trimmed 2 <br>'s

use preg_replace. strip excess whitespace (limit 1 space @ time):

$string = preg_replace('/\s\s+/', ' ', $string); 

you can research on how remove excess tags, preg_replace operation using regular expressions.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -