<?php

defined('COT_CODE') or die('Wrong URL');

function cot_string_truncate_seach($search_text = '', $find = '', $symbolls = 100, $boldfind = true, $cuttext = '...')
{
  $search_text = strip_tags($search_text, '');
  $search_txt_length = strlen($search_text);
  $search_first_enter = strpos(strtolower($search_text), strtolower($find));
  $pad_left = $search_first_enter-$symbolls;
  $pad_right = $search_first_enter+$symbolls+5;
  if ($pad_right>$search_txt_length) $pad_right = $search_txt_length;
  if ($pad_left<0) $pad_left = '0';
  $search_text = substr($search_text, $pad_left, $pad_right);
  $fst_nbsp = strpos($search_text, " ");
  $lst_nbsp = strrpos($search_text, " ");
  $search_text = substr($search_text,$fst_nbsp,$lst_nbsp-$fst_nbsp);
  $search_text = str_replace (strtolower($find), ($boldfind ? "<b>" : '').strtolower($find).($boldfind ? "</b>" : ''),strtolower($search_text));

  return (!empty($search_text) ? $cuttext.$search_text.$cuttext : '');
}