function drupal_explode_tags
7.x common.inc | drupal_explode_tags($tags) |
6.x common.inc | drupal_explode_tags($tags) |
Explode a string of given tags into an array.
See also
5 calls to drupal_explode_tags()
- comment_unpublish_by_keyword_action_submit in drupal-6.x/
modules/ comment/ comment.module - Process comment_unpublish_by_keyword_action_form form submissions.
- node_unpublish_by_keyword_action_submit in drupal-6.x/
modules/ node/ node.module - taxonomy_autocomplete in drupal-6.x/
modules/ taxonomy/ taxonomy.pages.inc - Helper function for autocompletion
- taxonomy_link in drupal-6.x/
modules/ taxonomy/ taxonomy.module - Implementation of hook_link().
- taxonomy_node_save in drupal-6.x/
modules/ taxonomy/ taxonomy.module - Save term associations for a given node.
File
- drupal-6.x/
includes/ common.inc, line 3765 - 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;
}