function Tags::explode
Same name in other branches
- 8.9.x core/lib/Drupal/Component/Utility/Tags.php \Drupal\Component\Utility\Tags::explode()
- 10 core/lib/Drupal/Component/Utility/Tags.php \Drupal\Component\Utility\Tags::explode()
- 11.x core/lib/Drupal/Component/Utility/Tags.php \Drupal\Component\Utility\Tags::explode()
Explodes a string of tags into an array.
Parameters
string $tags: A string to explode.
Return value
array An array of tags.
8 calls to Tags::explode()
- EntityAutocomplete::validateEntityAutocomplete in core/
lib/ Drupal/ Core/ Entity/ Element/ EntityAutocomplete.php - Form element validation handler for entity_autocomplete elements.
- EntityAutocompleteController::handleAutocomplete in core/
modules/ system/ src/ Controller/ EntityAutocompleteController.php - Autocomplete the label of an entity.
- TagsTest::explodeTags in core/
tests/ Drupal/ Tests/ Core/ Common/ TagsTest.php - Explodes a series of tags.
- TagsTest::testImplodeTags in core/
tests/ Drupal/ Tests/ Core/ Common/ TagsTest.php - Implodes a series of tags.
- UnpublishByKeywordComment::submitConfigurationForm in core/
modules/ comment/ src/ Plugin/ Action/ UnpublishByKeywordComment.php - Form submission handler.
File
-
core/
lib/ Drupal/ Component/ Utility/ Tags.php, line 21
Class
- Tags
- Defines a class that can explode and implode tags.
Namespace
Drupal\Component\UtilityCode
public static function explode($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 = [];
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.