View Full Version : Replace Text
amykhar
03-12-2003, 10:00 PM
This is more of a getting you started piece of code than a copy and paste your board is hacked kind of release. If you don't know how to code in PHP, this hack is NOT for you.
What this "hack" does is it allows you to replace a word in a post with something else. It doesn't replace the word in titles or anywhere else like replacements do. Just in a post.
What I use it for: I replace the word Netflix in every post with a link to my Netflix affilliate.
What you might use it for: affilliate links, swear word replacements with style, pranks, whatever :D
You will need to modify the function that I have included to set up your own replacement words. You might want to replace more than one thing. It's up to you. Have fun with this and share what you have done.
Demo:
http://www.eaforums.com/forums/showthread.php?s=&threadid=22557
I will help as much as I can in customizing this for you within reason.
FleaBag
03-14-2003, 12:27 AM
Useful for updating smilie names, I'll check it out sometime. Nice work! :)
Boofo
03-14-2003, 12:28 AM
I don't mean to sound negative, but can't you do the same thing with tags in vbcode without hacking? ;)
filburt1
03-14-2003, 12:40 AM
The idea is you just type Netflix and it happens to turn into an affiliate link.
Boofo
03-14-2003, 01:11 AM
I understand that. But a tag would be more versatile instead of having to hack the php file every time you wanted to change it. But to each his own, I guess.
How is this different from the Replacement Variable system? I use it to replace the phrase "closednow" with an image of a padlock, sort of a funny tradition on my forums. Works for me.
Merjawy
03-14-2003, 03:16 AM
I think this is more of a filter wich is biult in vB but doesn't work well with other languages... at least it didn't work for me
this could be a better way to make it censer certain words ..
Erwin
03-14-2003, 04:41 AM
What this hack does is it replaces the word with a link or whatever you want retrospectively as well (I think). Also, it's better than replacement, as replacement affects post titles, whereas this doesn't (from what I can understand).
amykhar
03-14-2003, 01:14 PM
Erwin is correct. Replacements changed the word in thread titles, as well, which then effectively rendered the thread unreadable because it became a link to Netflix.
I didn't use vbbcode because I don't want to have to edit each post and I don't want to have to rely on the membership to put it in.
I use this in conjunction with a hack Logician wrote for me eons ago that changes any link somebody posts to Amazon to a link that uses my affilliate ID. That hack helped quite a bit; so I am trying to expand slowly into other relevant affiliates.
Amy
wow i was just thinking of doing something like this. Im ganna build a page (might use the glossery hack) and have said word link to the glossery when its typed. this saves me some time :)
* Brad licks install
amykhar
03-14-2003, 01:50 PM
If you lick the install button, nobody else is going to want to touch it to click it. ;)
Amy
Theres a reason we have paper towels ;).
Dean C
03-14-2003, 03:59 PM
This is a very nice idea.. /me likes
- miSt
SgtSling
03-15-2003, 03:22 AM
weird
if someone types in Amazon.com it posts it.. but if someone types amazon all lowercase.. it doesn't
limey
03-15-2003, 04:10 AM
And to create more words we have to create more functions with:
($text1)
($text2)
($text3)
etc. right?
I'm pretty sure I'm right; just confirming ;). Very cool btw!
SgtSling
03-15-2003, 04:31 AM
yeah but if the poster links to a certain page..
like amazon.com/apage.html
it screws with the hyperlink
amykhar
03-15-2003, 12:37 PM
Today at 01:10 AM limey said this in Post #15 (https://vborg.vbsupport.ru/showthread.php?postid=366513#post366513)
And to create more words we have to create more functions with:
($text1)
($text2)
($text3)
etc. right?
I'm pretty sure I'm right; just confirming ;). Very cool btw!
No. You can actually do all of the replacements in the same function. If you look at the code, you can see that I replaced two different words: Netflix and netflix. You can do yours in the same way if you understand how the code works.
You would add code something along the lines of:
$affiliate_code2="Some other replacement string";
$text = str_replace("word2",$affiliate_code2,$text);
amykhar
03-15-2003, 12:39 PM
Today at 01:31 AM SgtSling said this in Post #16 (https://vborg.vbsupport.ru/showthread.php?postid=366516#post366516)
yeah but if the poster links to a certain page..
like amazon.com/apage.html
it screws with the hyperlink
With a bit more work, you could code it to ensure that the word you are replacing is not already in a URL. If I get some time today, I will play with it and give you the code.
Amy
amykhar
03-15-2003, 01:05 PM
Today at 12:22 AM SgtSling said this in Post #14 (https://vborg.vbsupport.ru/showthread.php?postid=366498#post366498)
weird
if someone types in Amazon.com it posts it.. but if someone types amazon all lowercase.. it doesn't
That is now fixed. See the new text file. To "upgrade" you will need to change calls of str_replace to stri_replace and add the new function stri_replace at the bottom of functions.php as outlined in the updated text file.
Amy
Derek
03-15-2003, 05:34 PM
Have you fixed it so that it doesn't mess up with someone types in amazon.com/apage.html so it doesn't screw with the URL? If it does, I will install.
amykhar
03-15-2003, 08:10 PM
Not yet, Derek. However, if you only want it for Amazon, Logician wrote a nice Amazon-specific version for me a year or so ago that is made for links.
Amy
SgtSling
03-16-2003, 10:40 PM
where is that at then?
amykhar
03-16-2003, 11:08 PM
<a href="https://vborg.vbsupport.ru/showthread.php?s=&threadid=39071&highlight=Amazon" target="_blank">https://vborg.vbsupport.ru/showt...ghlight=Amazon</a>
ImportPassion
04-30-2003, 03:42 PM
is there a way to use this for an ebay afilliate program?
Reason I ask is cause the urls need to be altered with the actual code of an = or ?
ie.
http://www.qksrv.net/click-1168523-5463217?loc=http%3A//cgi.ebay.com/ebaymotors/ws/eBayISAPI.dll%3FViewItem%26item%3D2413125104
it has to be exactly like this or you get an error if you change %3F to a ?
also, if someone posts a full url to an item, that is not just a word, i guess it can't do this yet from what i read?
Thanks,
Derek
gerlando
05-14-2003, 09:55 PM
This hack would be a lot more useful if it was an expansion to Logician's Amazon code.
amykhar
05-15-2003, 01:16 AM
Well, then expand it if you need it :D
Amy
limey
06-01-2003, 08:01 PM
got this working for 2.3?
amykhar
06-01-2003, 08:42 PM
Yes.
Chris M
06-01-2003, 08:48 PM
Nice idea amy;):)
Satan
limey
06-02-2003, 01:30 AM
When the correct phrase is typed in html link is the output, but its text and not linkable. Anyway to make it just show FOO linked?
Ive seen this output on your site as well Amy for the Netflix code. Is this way its supposed to be?
<a href="http://www.foo.com/index.html?fooAffilID=716" TARGET="_top">FOO</a>
thanks again.
amykhar
06-02-2003, 01:50 AM
Not sure what you are asking Limey
limey
06-02-2003, 01:57 AM
Ok go to this link:
http://www.eaforums.com/forums/showthread.php?threadid=19853&highlight=netflix
Goto Joubert's post. The output from the hack is not linkable. I'm seeing the same output of html on the site. I was wondering if there was a way to make the output a real link and not just text.
Hope I'm not confusing ya! :D
xone9
06-06-2003, 04:43 PM
is this still working?
amykhar
06-06-2003, 07:14 PM
Limey, It's not working on my site right this second because I have a clean functions.php installed. My functions.php was corrupted a few days ago and I haven't rehacked it.
Amy
amykhar
06-06-2003, 07:14 PM
Xone, yes it still works.
Amy
limey
06-07-2003, 04:07 AM
I have the hacked functions and its doing the same thing on my site as it is on your site. Very weird.
limey
06-07-2003, 04:13 AM
<a href="http://www.pokeritis.com/forums/showthread.php?threadid=11612" target="_blank">my example</a>
gmarik
06-07-2003, 05:56 AM
Great! If it would for titles - it would be ven better!
Darax The Good
06-07-2003, 07:51 AM
I can't seem to get this to work. My problem is that I can't find the proper place to put stri_replace. The doc says to find
[code[]?> [/code[]
but I can't seem to find that in functions.php. What am I missing?
Darax The Good
06-07-2003, 08:10 AM
I shoved the code from stri_replace into the handler for the text replacer and it works. Now the trick is-how do I get this to execute before the censor?
Darax The Good
06-07-2003, 08:26 AM
okay, I'm calling the handler function from the CensorText(). This allows the hack to work for titles too. There might be perf implications that I'm not aware of.
limey
06-08-2003, 05:19 AM
darax: the bit of [code ]?[/code ] is a mistake...its not in the functions file. Its meant to place that code above the ? at the end of the file.
Darax The Good
06-08-2003, 08:37 AM
coo limey-I tried that and bugger it didn't work, so I just put the code straight into the first function.
I'm not sure if anyone would care what I did, but I essentially replaced the swearbot. I call the below function toward the beginning of CensorText- I have a feeling you'll see a lot of ****'s there, but on the board we're setting up, we replace s... with poop, etc. If anything falls through the swearbot will catch it.
function CustomTextReplace($text){
//
//These two arrays should be obvious-but please take care that MyStrings has a counterpart in MyReplacements, or crash
//
$MyStrings = array(1=> "++++","++++","ass","+++++", "penis", "Garp",
7=>"promoteme", "kingsofchaos", "facial", "rotten.com", "outwar",
12=>"druglords", "goatse", "dildo", "nigger", "pussy",
17=>"++++++", "somethingawful", "Kazaa", "imesh",
21=>"Grokster", "feetman", "XoloX");
$MyReplacements = array(1=>"poop", "fark", "mule", "turkey", "chicken", "Flavor Dog",
7=>"teamxbox", "teamxbox", "manicure", "teamxbox.com", "teamxbox",
12=>"teamxbox", "teamxbox", "Bilbo Baggins", "I am a total moron", "kitten",
17=>"cat", "teamxbox", "(I would like to point out that I buy my music)", "what",
21=>"(stealing music is wrong BTW)", "what", "what");
$a=1;
//
//Loop through the strings-can we use a foreach here?
//
while($MyStrings[$a] <> ""){
//
//This section of code I got from vb.org, I know it scans the string and replaces
//but I'm not sure how...
//
$parts = explode( strtolower($MyStrings[$a]), strtolower($text) );
$pos = 0;
//
//This is especially cryptic...key...part? What?
//
foreach( $parts as $key=>$part )
{
$parts[ $key ] = substr($text, $pos, strlen($part));
$pos += strlen($part) + strlen($MyStrings[$a]);
}
$text=join( $MyReplacements[$a], $parts);
$a++;
}
//
//And Back We Go
//
return $text;
}
ryancooper
06-19-2003, 10:03 PM
OK I got this working but when it puts the link in I get the code on the screen? check it out: http://talkdisney.com/forums/showthread.php?s=&postid=189384#post189384
amykhar
06-19-2003, 10:49 PM
You have HTML turned off in the forum. Either change the code to replace to vbb, or turn on HTML.
ryancooper
06-19-2003, 11:16 PM
Amy Thank you for your response. I have altered the code to VBB but it still gives me the code?
Also I get a error when I try to change the image to a [img] tag
could you post the vbb version?
I am turning on html for the mean time!
:banana: Thanks!!
limey
06-23-2003, 03:10 PM
Yeh the VB code version would be great. This was my problem as well.
Not turning on HTML that is.
limey
06-25-2003, 03:22 PM
So does anyone know how to convert to VB code?
limey
06-29-2003, 05:47 PM
nothing on this eh?
limey
07-05-2003, 03:16 PM
Has anyone gotten this to work without turning on HTML in their forums? I thought that was a big security risk? I would like to get this to work so it posts with VB url code, but can't seem to figure it out.
thanks.
Has anyone gotten this to work without turning on HTML in their forums? I thought that was a big security risk? I would like to get this to work so it posts with VB url code, but can't seem to figure it out.
thanks.
Yes, it's very simple to do it without HTML ON!!!!!!!
function affiliateparse($text) {
$affiliate_code = "[ URL=http://www.google.com ]Google[ /URL ]";
$text = stri_replace("Google",$affiliate_code,$text);
return $text;
}
PS:
Remove the Spaces ;)
limey
10-19-2003, 03:45 PM
Yeh but can you pull images? It pulls the url for me.
limey
10-19-2003, 04:40 PM
Can you do mulitple keywords like "johnny","johnny2" ?
Yeh but can you pull images? It pulls the url for me.
You mean an image as an URL?
Then it would be like:
function affiliateparse($text) {
$affiliate_code = "[ URL=http://www.google.com ][ img]http://www.site.com/yourimage[ /img][ /URL ]";
$text = stri_replace("Google",$affiliate_code,$text);
return $text;
}
PS:
Remove the Spaces ;)
function affiliateparse($text) {
$affiliate_code1 = "[ URL=http://www.google.com ][ img]http://www.site.com/yourimage[ /img][ /URL ]";
$text = stri_replace("Google",$affiliate_code1,$text);
$affiliate_code2 = "[ URL=http://www.google.com ][ img]http://www.site.com/yourimage[ /img][ /URL ]";
$text = stri_replace("Google",$affiliate_code2,$text);
return $text;
}
ImportPassion
12-28-2003, 03:41 AM
so what happens when someone puts the keyword in a URL on their own?
Does the link get messed up?
ImportPassion
12-28-2003, 04:12 AM
yup, just found out that is does. damn, this would have been good.
limey
01-06-2004, 08:13 PM
This still work for vb3?
yellowbird
06-23-2004, 02:48 AM
How about a VB3 version? Anyone?
yellowbird
07-31-2004, 02:07 AM
Someone? Anyone?
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.