Forum Moderators: coopster
For instance: Search for "widget"
Replace all instances of "widget" with <a href="www.widget.com/widgets">widget</a>
I imagine this is possible, but don't know how to do it.
Thanks.
UPDATE table SET field = REPLACE("before", "after", field);
(you'll have the check if that's the right function name and syntax)
I strongly recommend NOT doing this in the database however, but on the PHP-side when you extract the text for a page. There are many reasons for this.
Why do you recommend not doing it in MySQL? I plan to do this for a potentially large number of keywords. I don't think that replacing the keywords on the fly would be very efficient.
;)
I plan to do this for a potentially large number of keywords. I don't think that replacing the keywords on the fly would be very efficient.
I agree with dcrombie. You'd be giving away a lot of the flexibility you bought by using a database if you crank these links into your data. This is all about making your life easier down the road.
You probably don't want to put a large number of "replace" lines into the PHP code. I'd suggest making a meta-data table, containing your keywords and their corresponding links. Just loop through them to make your replaces.
BTW, for just changing keywords, you may be able to get away with using str_ireplace which I hear tell is a little faster than regex replaces.
If you're still set on putting the links into your data, do yourself a favor and don't change the original data. Crank the new data into different columns.