mcbeav
mcbeav

Reputation: 12275

issue with a php tag system

I am trying to set up a tagging system, but i am having a little diffuculty here, if someone could help i would be very appreciative, anyhow i am just trying to query the database for the tags which are stuck into a row in the database of a table, and each tag is seperated by a comma, well i am trying to take each of those tags and create a link out of each one.

once i query the database the output basically looks as follows:

tag1, tag2, tag3, tag4, tag5, tag6

and i want to be able to separate them.

Upvotes: 0

Views: 1006

Answers (2)

user499054
user499054

Reputation:

If you already have a comma seperated value from the database, you can use a regex to print out the tags:

echo preg_replace( "/([a-z]+)/", "<a href=\"#$1\">$1</a>", $str ); It just goes through searching for a-z words and converts them in to links.

Some other options could be:

  • preg_replace_callback()
  • explode() (as the other user said)

Upvotes: 2

Vamsi Krishna B
Vamsi Krishna B

Reputation: 11490

This is a very good way of implementing tagging system.

http://www.phpro.org/tutorials/Tagging-With-PHP-And-MySQL.html

other way is using explode()

Upvotes: 1

Related Questions