AndyPSV Posted October 27, 2011 Share Posted October 27, 2011 after '', "" the script does unnecessary <br /> (or rather: "\r\n"); when those signs aren't present, it works fine how to remove the unnecessary new line marks, after those signs? <?php $text = 'It feels good to be in the zone and not so good to be out of it -- whether below or above your comfort level. Money -- or lack thereof -- is just one of many ways to get there. \'\' aaa "" bb'; function trimBR($s,$wrap=0,$html=0) { if($html <> 0) $s = htmlspecialchars($s); $s = trim(nl2br(preg_replace('/(\r\n|\t|\n){2,}/',"\r\n",$s))); $s = str_replace('<br />',"\r\n",$s); if($wrap <> 0) $s = wordwrap($s,$wrap,"<br />",true); return $s; } echo nl2br(trimBR($text)); # echo nl2br($text); ?> Quote Link to comment Share on other sites More sharing options...
silkfire Posted October 28, 2011 Share Posted October 28, 2011 nl2br() will replace "\n" as well, not just "\r\n", maybe that's why? Quote Link to comment Share on other sites More sharing options...
AndyPSV Posted October 28, 2011 Author Share Posted October 28, 2011 probably yes, because I don't see any other possibility what to do to in order to make the script working as it should with removal of nl2br() & str_replace()? Quote Link to comment Share on other sites More sharing options...
AndyPSV Posted November 10, 2011 Author Share Posted November 10, 2011 done, thanks <?php $text = 'It feels good to be in the zone and not so good to be out of it -- whether below or above your comfort level. Money -- or lack thereof -- is just one of many ways to get there. \'\' aaa "" bb'; function trimBR($s,$wrap=0,$html=0) { if($html <> 0) $s = htmlspecialchars($s); $s = trim(preg_replace('/(\r\n|\t|\n){2,}/',"\r\n\r\n",$s)); if($wrap <> 0) $s = wordwrap($s,$wrap,"<br />",true); return $s; } echo trimBR($text); #echo nl2br($text); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.