• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 309
  • Last Modified:

Automatically link particular words on the website


I need to automatically link some words on my website, it's a dynamic website, so let's say someone makes a comment under the article: "Really nice article about London", and if i have set up word "London" to be a link to other website it becomes a link in the comment.

Thanks for help,
  • 2
1 Solution
jhmplondonAuthor Commented:
this is exactly what I'm looking for, however it's a wordpress plugin, and my website is custom made CMS, so it's not very helpful: http://www.blogperfume.com/plugin-automatically-link-keywords-phrases-in-posts/
Lukasz ChmielewskiCommented:
A preg_replace seems to be the way to go:
Lukasz ChmielewskiCommented:
Maybe this will help

$str = "This is some text about London and Prague. London is in England."; 
$str = preg_replace("/London/", "<a href=\"http://$0\">$0</a>", $str); 
echo $str;


Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now