Issue with commas and tags [solved]

I’m a PHP newbie and I’ve done some googling and Stack Overflowing, but I haven’t had much luck figuring out something that seems like it should be relatively simple. Here’s my question:

When echoing $x->tags(), is it possible to strip out the comma character which follows each tag? I’m using a foreach loop for list items which represent individual pages, and I’d like to pass each li an array of classes that correspond with the tags associated with that page. The current output of class=“tag1, tag2, tag3” is making this difficult.

Any suggestions?

<?php
// Array
$classes = explode(",", $page->tags());
// String
$classes = strtr($page->tags(), ",", "");

Amazing!

Interestingly, I had to insert a blank space in between the second pair of quotes before it would actually replace the comma characters, but I’ll dig into that later. Thanks so much, this is great!

Have a look at the split field method! That’s exactly what you’re looking for and results in less code. :wink:

@twirx Okay, I figured there would be a method like that built into Kirby — I just couldn’t seem to find it.

Looks like I learned a little bit more about both Kirby and PHP. :slight_smile: