Shane
Shane

Reputation: 244

Separate tags from database

I am building a blog which has tags.

The tags are saved to the DB like so tag1,tag2,tag3 I would like to display these separately is there a way to separate these when echoing them out?

Thanks

Upvotes: 0

Views: 79

Answers (1)

daniel__
daniel__

Reputation: 11845

$pizza  = "piece1,piece2,piece3,piece4,piece5";
$pieces = explode(",", $pizza);
echo $pieces[0]; // piece1
echo $pieces[1]; // piece2

Use count with a for loop or just a foreach to iterate over the array $pieces

foreach($pieces as $key => $value) {
    echo $value;
}

Source

Demo

Upvotes: 1

Related Questions