• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/functions.php
  • Класс: CSocNetTextParser
  • Вызов: CSocNetTextParser::closetags
static function closetags($html)
{
	$arNoClose = array('br','hr','img','area','base','basefont','col','frame','input','isindex','link','meta','param');

	preg_match_all("#<([a-z0-9]+)([^>]*)(?#i".BX_UTF_PCRE_MODIFIER, $html, $result);
	$openedtags = $result[1];

	preg_match_all("##i".BX_UTF_PCRE_MODIFIER, $html, $result);
	$closedtags = $result[1];
	$len_opened = count($openedtags);

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

	$openedtags = array_reverse($openedtags);

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

	return $html;
}