• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/functions.php
  • Класс: CSocNetTextParser
  • Вызов: CSocNetTextParser::strip_words
function strip_words($string, $count)
{
	$result = "";
	$counter_plus  = true;
	$counter = 0;
	$string_len = mb_strlen($string);
	for($i=0; $i<$string_len; ++$i)
	{
		$char = mb_substr($string, $i, 1);
		if($char == '<')
			$counter_plus = false;
		if($char == '>' && mb_substr($string, $i + 1, 1) != '<')
		{
			$counter_plus = true;
			$counter--;
		}
		$result .= $char;
		if ($counter_plus)
			$counter++;
		if($counter >= $count)
		{
			$pos_space = mb_strpos($string, " ", $i);
			$pos_tag = mb_strpos($string, "<", $i);
			if ($pos_space == false)
			{
				$pos = mb_strrpos($result, " ");
				$result = mb_substr($result, 0, mb_strlen($result) - ($i - $pos + 1));
			}
			else
			{
				$pos = min($pos_space, $pos_tag);
				if ($pos != $i)
				{
					$dop_str = mb_substr($string, $i + 1, $pos - $i - 1);
					$result .= $dop_str;
				}
				else
					$result = mb_substr($result, 0, mb_strlen($result) - 1);
			}
			break;
		}
	}
	return $result;
}