Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 305
  • Last Modified:

Automatically link particular words on the website

Hi,

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,
Tom
0
jhmplondon
Asked:
jhmplondon
  • 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/
0
 
Lukasz ChmielewskiCommented:
A preg_replace seems to be the way to go:
http://php.bigresource.com/Track/php-b0w9M2EA/
0
 
Lukasz ChmielewskiCommented:
Maybe this will help
<?php

$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

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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