View Full Version : dynamic text to links
bigtree
10-19-2006, 10:56 PM
is it possible to have something where, whenever a particular word is written in my forum, it is turned into a link. I would like to do this for advertising. If someone mentions a product, that word automatically become a link to the manufacturers product information web site.
Cheers!
djr33
10-19-2006, 11:21 PM
Complex.
You could use php for this.
str_replace($text," product ",' <a href="product.com">product</a> ');
That should replace all instances of product with a link.
You would also want to account for using Product, PRODUCT, etc. if that mattered to you.
Additionally, using " product " and " <a ..../a> " is good 'cause you would have spaces around it, rather than replacing, for example, "biproduct", or some similar word that contain the word.... it will only do full words. (You could be more creative here, too.)
Just repeat for each product/etc.
However....
Here's the tricky part--
You would need to do this to a VARIABLE, not just the "whole page".
So... find some way of storing the html for the whole page as a variable in php.... either when it's taken from the database, etc.
Are you using a forum? You could just add this into the forum's existing code for formatting posts. It would be almost identical to the process used for emoticons.
The hard part is getting the page as a variable, not replacing the words... that's easy enough.
bigtree
10-20-2006, 02:46 AM
Hi djr33
I am using phpnuke. I would like to do this in the forums which are the phpbb2 Port by Tom Nitzschner. I'm not too code savy so I really apprciate your help here.
It would be ideal if it supported upper or lower case ( Sebatron or sebatron). and only write the link to the exact word. I have it working by using the forums word censor option however, it also rewrite/ links the word in the topic title. When it does that it breaks the original link of the topic. I only want this to work in the posts, not topic titles. If I could use this censor function for this and find a way to comment out it from including the title I'd possibly have it.
djr33
10-20-2006, 03:26 AM
You have to look through the source code and find where that function is, then add in custom php. It's hard to search through there... it's a maze.
Get to it :)
bigtree
10-21-2006, 02:23 AM
Could I simply add ( activate, deactivate, modify) something in phpMyAdmin and exclude titles ?
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.