function drupal_explode_tags
Explodes a string of tags into an array.
See also
6 calls to drupal_explode_tags()
- comment_unpublish_by_keyword_action_submit in modules/
comment/ comment.module - Process comment_unpublish_by_keyword_action_form form submissions.
- DrupalTagsHandlingTestCase::testDrupalExplodeTags in modules/
simpletest/ tests/ common.test - Explode a series of tags.
- DrupalTagsHandlingTestCase::testDrupalImplodeTags in modules/
simpletest/ tests/ common.test - Implode a series of tags.
- node_unpublish_by_keyword_action_submit in modules/
node/ node.module - Saves settings form for node_unpublish_by_keyword_action().
- taxonomy_autocomplete in modules/
taxonomy/ taxonomy.pages.inc - Page callback: Outputs JSON for taxonomy autocomplete suggestions.
File
-
includes/
common.inc, line 7800
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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.