Separate comma seperated values with links to each

Discussion in 'PHP' started by profs77, Sep 16, 2006.

  1. #1
    I'm making a site, lets just say it was a blog. Each thing has decription tags that are pulled from a mysql datatable which is seperated by a comma and a space An example might be:

    sprint, nextel, nextell, push, salt

    I want to be able to link every word to a search result page like search.php?q=sprint search.php?q=push search.php?q=nextell

    Any idea or codesnippets on how to do that?
     
    profs77, Sep 16, 2006 IP
  2. profs77

    profs77 Well-Known Member

    Messages:
    441
    Likes Received:
    39
    Best Answers:
    0
    Trophy Points:
    118
    #2
    I figured it out, this works exactly how I needed it.

      echo("Tags: ");
      $a = split(', ', $myrow['tags']);
      foreach ($a as $value) {
       echo("<a href=\"search.php?q=" . $value . "\">" . $value . "</a>, ");
      }
      echo("<br />");
    PHP:
     
    profs77, Sep 16, 2006 IP
  3. harsh789

    harsh789 Member

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    38
    #3
    It is batter to urlencode the search terms.

    echo("<a href=\"search.php?q=" . urlencode($value) . "\">" . $value . "</a>, ");
    PHP:
     
    harsh789, Sep 16, 2006 IP