The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Finding and chopping out multiple \n
OK I'll come clean at the start. I'm running vBulletin Version 1.1.5
on a "charity" site and the traffic doesn't warrant purchasing an upgrade. What I want to do is to add a small patch function that can be called at the same time as the existing function dowordwrap(). Some users of my BBS have discovered how much "fun" it can be to hold down the enter key when writing a message. It doesn't burden the board's bandwidth much but I want to stop it, anyway. The trouble is that I am not really sure how to begin writing an eregi_replace() expression that will do the job of finding sequences of >2 \n and replacing those instances with \n\n. Does anyone care to give me a line or so code that could enable me to take the existing function in global.php: function dowordwrap($wordwraptext) { global $wordwrap; if ($text!="") { $text=eregi_replace("([^\n\r \./<>\"\\-]{".$wordwrap."})"," \\1 ",$wordwraptext); } else { $text=$wordwraptext; } return $text; } so that I can modify it as a new function: (function dostriplinestext($text)) I can then ADD the new function to global.php . . . then I guess, all I need to do is find all the files that call that function and add in the lines necessary. Better still: could the dowordwrap() function be modded to do both jobs - or (I have searched) has the mod already been written? :ermm: I do realise that this patch wouldn't stop idiots hitting a-z followed by enter . . . but at least they would be taking some exercise . . .. Regards, Abby ( webmaster@iancollins.net ) ________________ version 2.2.6 rocks! I am jealous! |
#2
|
||||
|
||||
$text=str_replace("\n\n\n", "\n\n", $text);
or $text=preg_replace("/\n\n\n/", "\n\n", $text); |
#3
|
|||
|
|||
Quote:
Also what is the purpose of enclosing the searchstring expression inside the paired / /? And would this trap any number of /n or do I need to add something like {1,} giving something like: preg_replace("(\n\n\n){1,}","\n\n",$text); Plus would that iterate once only? What if $text== "hello"."\n\n\n\n\n\n\n\n\n\n\n\n"."good"."\n\n\n\ n\n\n\n\"."bye" (where the newline strings could be any length) Finally could the new string manipulation expression be added to the existing dowordwrap() function code block or would it be safer to add a completely new and separate function? Adding the code to dowordwrap() would leave me option of turn it on/off from the existing admin options. Thanks for taking the time to look at my problem. |
#4
|
||||
|
||||
preg_replace is faster than eregi_replace
preg_replace is PERL compatable, so inside the quotes, it needs to look exactly like a PERL regular expression (so I use / as a delimeter). The rest you can answer yourself by trying it. |
#5
|
||||
|
||||
I'm sorry Abby, we cannot support unlicensed users of vBulletin. Feel free to come back when you purchase a license.
|
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|