• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/lib/text.php
  • Класс: BitrixImText
  • Вызов: Text::convertHtmlToBbCode
static function convertHtmlToBbCode($html)
{
	if (!is_string($html))
	{
		return $html;
	}

	$html = str_replace(' ', ' ', $html);
	$html = str_replace('
', '------[BR]', $html); $html = str_replace('#BR#', '[BR]', $html); $replaced = 0; do { $html = preg_replace( "/<([busi])[^>a-z]*>(.+?)<\/(\1)[^>a-z]*>/is".BX_UTF_PCRE_MODIFIER, "[\1]\2[/\1]", $html, -1, $replaced ); } while($replaced > 0); $html = preg_replace("/\/is".BX_UTF_PCRE_MODIFIER,"[br]", $html); $html = preg_replace( [ "#]+href\s*=\s*('|")(.+?)(?:\1)[^>]*>(.*?)]*>#is".BX_UTF_PCRE_MODIFIER, "#]+href(\s*=\s*)([^'">]+)>(.*?)]*>#is".BX_UTF_PCRE_MODIFIER ], "[url=\2]\3[/url]", $html ); $html = preg_replace( ["/]+colors*=[s'"]*#([0-9a-f]{3}|[0-9a-f]{6})[s'"]*>(.+?)]*>/i".BX_UTF_PCRE_MODIFIER], ["[color=#\1]\2[/color]"], $html ); $html = preg_replace( ["/]+colors*=[s'"]*#([0-9a-f]{3}|[0-9a-f]{6})[s'"]*>(.+?)]*>/i".BX_UTF_PCRE_MODIFIER], ["[color=#\1]\2[/color]"], $html ); $html = preg_replace( ["/]+sizes*=[s'"]*(d+)[s'"]*>(.+?)]*>/i".BX_UTF_PCRE_MODIFIER], ["[size=\1]\2[/size]"], $html ); $replaced = 0; do { $html = preg_replace( "/(.*?)
/i".BX_UTF_PCRE_MODIFIER, "\1", $html, -1, $replaced ); } while($replaced > 0); $replaced = 0; do { $html = preg_replace( "/(.*?)/i".BX_UTF_PCRE_MODIFIER, "\1", $html, -1, $replaced ); } while($replaced > 0); $html = preg_replace( "/(.*?)/i".BX_UTF_PCRE_MODIFIER, "\1", $html ); return $html; }