Same name and namespace in other branches
  1. 7.x modules/taxonomy/taxonomy.module \taxonomy_implode_tags()
  2. 8.9.x core/modules/taxonomy/taxonomy.module \taxonomy_implode_tags()
  3. 9 core/modules/taxonomy/taxonomy.module \taxonomy_implode_tags()

Implodes a list of tags of a certain vocabulary into a string.

See also

drupal_explode_tags()

File

modules/taxonomy/taxonomy.module, line 1388
Enables the organization of content into categories.

Code

function taxonomy_implode_tags($tags, $vid = NULL) {
  $typed_tags = array();
  foreach ($tags as $tag) {

    // Extract terms belonging to the vocabulary in question.
    if (is_null($vid) || $tag->vid == $vid) {

      // Commas and quotes in tag names are special cases, so encode 'em.
      if (strpos($tag->name, ',') !== FALSE || strpos($tag->name, '"') !== FALSE) {
        $tag->name = '"' . str_replace('"', '""', $tag->name) . '"';
      }
      $typed_tags[] = $tag->name;
    }
  }
  return implode(', ', $typed_tags);
}