Same filename and directory in other branches
- 8.9.x core/lib/Drupal/Component/Utility/Tags.php
- 9 core/lib/Drupal/Component/Utility/Tags.php
Namespace
Drupal\Component\Utility
File
core/lib/Drupal/Component/Utility/Tags.php
View source
<?php
namespace Drupal\Component\Utility;
class Tags {
public static function explode($tags) {
$regexp = '%(?:^|,\\ *)("(?>[^"]*)(?>""[^"]* )*"|(?: [^",]*))%x';
preg_match_all($regexp, $tags, $matches);
$typed_tags = array_unique($matches[1]);
$tags = [];
foreach ($typed_tags as $tag) {
$tag = trim(str_replace('""', '"', preg_replace('/^"(.*)"$/', '\\1', $tag)));
if ($tag != "") {
$tags[] = $tag;
}
}
return $tags;
}
public static function encode($tag) {
if (str_contains($tag, ',') || str_contains($tag, '"')) {
return '"' . str_replace('"', '""', $tag) . '"';
}
return $tag;
}
public static function implode($tags) {
$encoded_tags = [];
foreach ($tags as $tag) {
$encoded_tags[] = self::encode($tag);
}
return implode(', ', $encoded_tags);
}
}
Classes
Name |
Description |
Tags |
Defines a class that can explode and implode tags. |