Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 05-17-2002, 10:54 AM
Roxy Rugrat Roxy Rugrat is offline
 
Join Date: May 2002
Posts: 2
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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!
Reply With Quote
  #2  
Old 05-17-2002, 03:55 PM
Mark Hensler's Avatar
Mark Hensler Mark Hensler is offline
 
Join Date: Oct 2001
Location: California
Posts: 205
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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

or

$text=preg_replace("/\n\n\n/", "\n\n", $text);
Reply With Quote
  #3  
Old 05-17-2002, 05:52 PM
Roxy Rugrat Roxy Rugrat is offline
 
Join Date: May 2002
Posts: 2
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #4  
Old 05-18-2002, 03:46 AM
Mark Hensler's Avatar
Mark Hensler Mark Hensler is offline
 
Join Date: Oct 2001
Location: California
Posts: 205
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #5  
Old 05-18-2002, 06:12 AM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:37 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.11386 seconds
  • Memory Usage 2,193KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete