View Full Version : specific word replacement
wolfyman
02-13-2010, 12:14 AM
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:
$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
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:
$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
$word = array(
'word 1',
'word 2',
);
$link = array(
'Replacement 1',
'Replacement 2',
);
$this->post['message'] = str_replace($word, $link, $this->post['message']);
--------------- Added 1266066243 at 1266066243 ---------------
or did I get the replacement values wrong? I don't understand what $link and $word do.
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
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
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:
$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
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
$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?
$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
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.