Automatically link particular words on the website

Posted on 2011-04-20
Last Modified: 2012-05-11

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,
Question by:jhmplondon

    Author Comment

    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:
    LVL 27

    Expert Comment

    by:Lukasz Chmielewski
    A preg_replace seems to be the way to go:
    LVL 27

    Accepted Solution

    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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Suggested Solutions

    Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now