vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Finding and chopping out multiple \n (https://vborg.vbsupport.ru/showthread.php?t=38734)

Roxy Rugrat 05-17-2002 10:54 AM

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!

Mark Hensler 05-17-2002 03:55 PM

$text=str_replace("\n\n\n", "\n\n", $text);

or

$text=preg_replace("/\n\n\n/", "\n\n", $text);

Roxy Rugrat 05-17-2002 05:52 PM

Quote:

Originally posted by Mark Hensler
$text=str_replace("\n\n\n", "\n\n", $text);

or

$text=preg_replace("/\n\n\n/", "\n\n", $text);

Ah, Mark, that second example.... I've not come across preg_replace() what's the difference between that and eregi_replace()???

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.

Mark Hensler 05-18-2002 03:46 AM

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.

Admin 05-18-2002 06:12 AM

I'm sorry Abby, we cannot support unlicensed users of vBulletin. Feel free to come back when you purchase a license.


All times are GMT. The time now is 12:32 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01092 seconds
  • Memory Usage 1,724KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete