function drupal_explode_tags

Explodes a string of tags into an array.

See also

drupal_implode_tags()

14 calls to drupal_explode_tags()
AutocompleteTagsUnitTest::testDrupalExplodeTags in drupal/core/modules/system/lib/Drupal/system/Tests/Common/AutocompleteTagsUnitTest.php
Explodes a series of tags.
AutocompleteTagsUnitTest::testDrupalImplodeTags in drupal/core/modules/system/lib/Drupal/system/Tests/Common/AutocompleteTagsUnitTest.php
Implodes a series of tags.
comment_unpublish_by_keyword_action_submit in drupal/core/modules/comment/comment.module
Form submission handler for comment_unpublish_by_keyword_action_form().
Name::validateExposed in drupal/core/modules/user/lib/Drupal/user/Plugin/views/filter/Name.php
Validate the exposed handler form
Name::value_validate in drupal/core/modules/user/lib/Drupal/user/Plugin/views/filter/Name.php
Validate the options form.

... See full list

File

drupal/core/includes/common.inc, line 6495
Common functions that many Drupal modules will need to reference.

Code

function drupal_explode_tags($tags) {

  // This regexp allows the following types of user input:
  // this, "somecompany, llc", "and ""this"" w,o.rks", foo bar
  $regexp = '%(?:^|,\\ *)("(?>[^"]*)(?>""[^"]* )*"|(?: [^",]*))%x';
  preg_match_all($regexp, $tags, $matches);
  $typed_tags = array_unique($matches[1]);
  $tags = array();
  foreach ($typed_tags as $tag) {

    // If a user has escaped a term (to demonstrate that it is a group,
    // or includes a comma or quote character), we remove the escape
    // formatting so to save the term into the database as the user intends.
    $tag = trim(str_replace('""', '"', preg_replace('/^"(.*)"$/', '\\1', $tag)));
    if ($tag != "") {
      $tags[] = $tag;
    }
  }
  return $tags;
}