• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/classes/general/textparser.php
  • Класс: CTextParser
  • Вызов: CTextParser::closeTags
static function closeTags($html)
{
	preg_match_all("#<([a-z0-9]+)([^>]*)(?#i" . BX_UTF_PCRE_MODIFIER, $html, $result);
	$openedtags = array_map('strtolower', $result[1]);

	preg_match_all("##i" . BX_UTF_PCRE_MODIFIER, $html, $result);
	$closedtags = array_map('strtolower', $result[1]);

	$len_opened = count($openedtags);

	if (count($closedtags) == $len_opened)
	{
		return $html;
	}

	$openedtags = array_reverse($openedtags);

	static $tagsWithoutClose = ['input'=>1, 'img'=>1, 'br'=>1, 'hr'=>1, 'meta'=>1, 'area'=>1, 'base'=>1, 'col'=>1, 'embed'=>1, 'keygen'=>1, 'link'=>1, 'param'=>1, 'source'=>1, 'track'=>1, 'wbr'=>1];

	for ($i = 0; $i < $len_opened; $i++)
	{
		if (isset($tagsWithoutClose[$openedtags[$i]]))
		{
			continue;
		}
		if (!in_array($openedtags[$i], $closedtags))
		{
			$html .= '';
		}
		else
		{
			unset($closedtags[array_search($openedtags[$i], $closedtags)]);
		}
	}

	return $html;
}