Text array to links

Discussion in 'PHP' started by teamshop, Oct 21, 2005.

  1. #1
    I have a keyword field in a mysql database that I am trying to break down each comma separated phrase in the field and make them into clickable links.

    i.e keyword keyword2 keyword3....

    I am using $words = explode(",", $keywords); to breakdown the data to single phrases contained in an array but need to figure out how to break the array down into clickable links (i.e /search.php?t=$words) for each individual phrase. Assuming that it should be easy but my PHP isn't the greatest.

    Any suggestions greatly appreciated
     
    teamshop, Oct 21, 2005 IP
  2. durango

    durango Guest

    Messages:
    83
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try this:

    
    <?php
    foreach ( explode(",",$keywords) as $word ) {
        echo "<a href=\"/search.php?t=$word\">$word</a>&nbsp;";
    }
    ?>
    
    Code (markup):
     
    durango, Oct 21, 2005 IP
  3. teamshop

    teamshop Plainsman

    Messages:
    345
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks durango, words like a charm.
     
    teamshop, Oct 21, 2005 IP