vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   specific word replacement (https://vborg.vbsupport.ru/showthread.php?t=235725)

wolfyman 02-13-2010 12:14 AM

specific word replacement
 
I know how to replace a list of words with *.... but what if I want to replace words on a word-by-word basis?

"Cat " to "Dog"
"Bear" to "Pig"
"XXX" to "YYY"

etc?

Is that possible?

Lynne 02-13-2010 03:44 AM

Sure, just use a plugin to do a str_replace. I think I've written the code for this quite a few times - here's a copy from another thread:
PHP Code:

$word = array(
'word 1',
'word 2',
);
$link = array(
'xxxx',
'yyyy',
);
$this->post['message'] = str_replace($word$link$this->post['message']); 

It should work in vB4, I think.

wolfyman 02-13-2010 11:02 AM

Quote:

Originally Posted by Lynne (Post 1981170)
Sure, just use a plugin to do a str_replace. I think I've written the code for this quite a few times - here's a copy from another thread:
PHP Code:

$word = array(
'word 1',
'word 2',
);
$link = array(
'xxxx',
'yyyy',
);
$this->post['message'] = str_replace($word$link$this->post['message']); 

It should work in vB4, I think.

So to make a plugin I go to

Plugins & Products > Add new Plugin

Then I need:

Product type: ?
Hook Location: ?
Title: Custom Word Replacement
Execution Order: ?

Plugin PHP Code

PHP Code:

$word = array(
'word 1',
'word 2',
);
$link = array(
'Replacement 1',
'Replacement 2',
);
$this->post['message'] = str_replace($word$link$this->post['message']); 

--------------- Added [DATE]1266066243[/DATE] at [TIME]1266066243[/TIME] ---------------

or did I get the replacement values wrong? I don't understand what $link and $word do.

Andy 02-13-2010 04:06 PM

Here are instructions on how to create a plugin to Replace Words in the pagetext.

https://vborg.vbsupport.ru/showthread.php?t=235769

wolfyman 02-19-2010 01:24 PM

Quote:

Originally Posted by Andy (Post 1981448)
Here are instructions on how to create a plugin to Replace Words in the pagetext.

https://vborg.vbsupport.ru/showthread.php?t=235769

perfect, thanks :)

wolfyman 02-22-2010 01:49 PM

Quote:

Originally Posted by wolfyman (Post 1987417)
alert!

I installed this and thought it was working great.. but for some reason, the Replace Word postdata plugin causes a weird error.

With this enabled, when you move a thread from one forum to another.... the first post gets stripped of data.

wtf is that all about?!

Here is my php code:

PHP Code:

$search = array(
'this1',
'this2',
);
$replace = array(
'that1',
'that 2',
);
$this->post['pagetext'] = str_replace($search$replace$this->post['pagetext']); 


Any ideas out there?

Lynne 02-22-2010 10:01 PM

I've never had any problems with mine. The difference between ours is what we apply it to (pagetext versus message), so perhaps that has something to do with it.

wolfyman 02-23-2010 12:38 AM

how do you do that?

I need it in terms a 6 year old can understand :)

Lynne 02-23-2010 01:04 AM

What do you mean? I'm talking about the difference in our plugins. I posted what I use in post 2 and I do a replace for $this->post['message'] whereas you do a replace for $this->post['pagetext']

wolfyman 02-23-2010 01:15 PM

so the code stays the same, I just replace 'pagetext' with 'message'?


All times are GMT. The time now is 01:52 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.01588 seconds
  • Memory Usage 1,747KB
  • 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
  • (4)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete