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'?

Lynne 02-23-2010 01:59 PM

Quote:

Originally Posted by wolfyman (Post 1989595)
so the code stays the same, I just replace 'pagetext' with 'message'?

I posted what I use above and it looks like we just do the replace on a different field. (Although the are closely related.) It could be that your search/replace is not playing nice with some regular stuff on the page, but without seeing exactly what you have in the plugin, it is hard to tell.

wolfyman 02-23-2010 02:10 PM

this is my plugin

PHP Code:

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


Lynne 02-23-2010 02:15 PM

I can't think of why that would cause the issue you are seeing. I just took a look at that link and it looks like it tells you to make two plugins at different locations. You may want to ask for help in that modification thread for this. I really don't know why he uses those locations unless he is actually changing the text before it's saved? The way I was doing it just changes the output. Anyway, you really should be asking for help in the modification thread and see if others have had the same issue.

wolfyman 02-25-2010 11:39 PM

I'd prefer to do it your way, but I don't understand exactly how it's done. Is this your plugin? What hook do you use?

PHP Code:

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

Thank you lynne

Lynne 02-25-2010 11:47 PM

I just used postbit_display_complete


All times are GMT. The time now is 01:08 PM.

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.02527 seconds
  • Memory Usage 1,763KB
  • 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
  • (6)bbcode_php_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (15)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