$maxLength) throw new SimpleException('Tag must have at most ' . $maxLength . ' characters'); if (!preg_match('/^[a-zA-Z0-9_-]+$/i', $tag)) throw new SimpleException('Invalid tag "' . $tag . '"'); return $tag; } public static function validateTags($tags) { $tags = trim($tags); $tags = preg_split('/[,;\s]+/', $tags); $tags = array_filter($tags, function($x) { return $x != ''; }); $tags = array_unique($tags); foreach ($tags as $key => $tag) $tags[$key] = self::validateTag($tag); if (empty($tags)) throw new SimpleException('No tags set'); return $tags; } }