News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Limit excess line breaks within posts, pm's, etc.

Started by Chen Zhen, May 04, 2014, 11:59:16 AM

Previous topic - Next topic

Chen Zhen

Limit Line Breaks

  The edit shown below will limit excess line breaks within posts, pm's, etc. if you wish to restrict this input on your forum.
The example uses 3 as the limit whereas one can change that number to the desired limit.
This only involves adding 2 lines of code so I thought it best to post it in this section as opposed to creating a mod for it.

File: ../Sources/Load.php

find:

// Replace all vulgar words with respective proper words. (substring or whole words..)
function &censorText(&$text, $force = false)
{
global $modSettings, $options, $settings, $txt;
static $censor_vulgar = null, $censor_proper;


add after the above code:

        $limitBreaks = 3;
        $text = preg_replace("#(?:(\<br( />)){" . $limitBreaks . ",})#m", str_repeat("<br />", $limitBreaks), $text);





I believe that is the only type of line break within a post or pm therefore the above regex should suffice.
However, if for some reason one needs to handle carriage returns then use the following edit:

        $limitBreaks = 3;
        $text = preg_replace("#(?:(\\n|\\r|\<br( />)){" . $limitBreaks . ",})#m", str_repeat("<br />", $limitBreaks), $text);


Regards.

My SMF Mods & Plug-Ins

WebDev

"Either you repeat the same conventional doctrines everybody is saying, or else you say something true, and it will sound like it's from Neptune." - Noam Chomsky

Advertisement: