surfwtw Posted March 3, 2012 Share Posted March 3, 2012 Below is the code I have so far for only 2 terms with '$word" being the keyword of the site and all the other words are suppose to be linked if they appear in the text. Okay I have thousands of different possible words from the same table. In the table 'word' is the term to be defined and 'definition' is the main content. I want a code that recognizes any word that is listed in my table and replaces it. <?php $find2 = array ('/$word/i', '/bond/i'); $replace2 = array ('<a href=http://www.subjectmoney.com/definitiondisplay.php?word=$word><b>$word</b></a>', '<a href=http://www.subjectmoney.com/definitiondisplay.php?word=Bond>bond</a>'); Echo preg_replace ($find2, $replace2, $definition); ?> Quote Link to comment https://forums.phpfreaks.com/topic/258157-preg_replace-thousands-of-arrays-from-table/ Share on other sites More sharing options...
dannyb785 Posted March 3, 2012 Share Posted March 3, 2012 There's the easy, but more resource-consuming way: make a php script that grabs every row from the table, do a while($row = mysql_fetch_assoc($result)) and in each iteration, do the preg_replace for the specified variable and then do a mysql UPDATE to modify that row I know there's a way to do the search/replace using mysql(provided the $find2 in question is the same for every record) using a find/replace query, but I don't know mysql well enough to be able to help you with that Quote Link to comment https://forums.phpfreaks.com/topic/258157-preg_replace-thousands-of-arrays-from-table/#findComment-1323376 Share on other sites More sharing options...
QuickOldCar Posted March 3, 2012 Share Posted March 3, 2012 I think you are making this hard on yourself. If you have the words in the database already, why are you trying to add all the href links to them in the database, that's a lot more information than you need to store. Just echo whatever result for word as a hyperlink on display. echo "<a href='definitiondisplay.php?word=$word'><b>$word</b></a>"; I believe if you write what the complete goal are trying to accomplish, is a better way to do it. Quote Link to comment https://forums.phpfreaks.com/topic/258157-preg_replace-thousands-of-arrays-from-table/#findComment-1323404 Share on other sites More sharing options...
surfwtw Posted March 3, 2012 Author Share Posted March 3, 2012 I want key words on my website to be linked for efficiency reasons for my customers and for SEO purposes. When people are reading an article and they come across a word they don't know, I want it to be linked the way they are in wikipedia. Quote Link to comment https://forums.phpfreaks.com/topic/258157-preg_replace-thousands-of-arrays-from-table/#findComment-1323555 Share on other sites More sharing options...
dannyb785 Posted March 3, 2012 Share Posted March 3, 2012 I want key words on my website to be linked for efficiency reasons for my customers and for SEO purposes. When people are reading an article and they come across a word they don't know, I want it to be linked the way they are in wikipedia. You may not understand what he(who posted above you) meant. Anytime the text is displayed on a web page, it would convert the keyword into a link, so any web crawler would see the hyperlink. It's just in the table itself that there would be no link; and crawlers don't access database tables to index their results so his way is totally fine Quote Link to comment https://forums.phpfreaks.com/topic/258157-preg_replace-thousands-of-arrays-from-table/#findComment-1323592 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.