I am using the below code to truncate my content before and after the first search keyword in my text
(this is for my search page)
function neatest_trim($content, $chars, $searchquery,$characters_before,$characters_after) {
if (strlen($content) > $chars) {
$pos = strpos($content, $searchquery);
$start = $characters_before < $pos ? $pos - $characters_before : 0;
$start = strpos($content, " ", $start);
$len = $pos + strlen($searchquery) + $characters_after - $start;
$content = str_replace(' ', ' ', $content);
$content = str_replace("\n", '', $content);
$content = strip_tags(trim($content));
$content = preg_replace('/\s+?(\S+)?$/', '', mb_substr($content, $start, $len));
$content = trim($content) . '...';
$content = strip_tags($content);
$content = str_ireplace($searchquery, '<b>' . $searchquery . '</b>', $content);
}
return $content;
}
$content = '
lients at the centre of the relationship and to offer a first class service to them which includes tax planning investment management and estate planning. We believe that our customer focused and
';
$searchquery = 'the centre includes';
echo neatest_trim($content,0,$searchquery,0,50);
example my finded post with below keyword :
in below string :
and i want to show below output:
at the centre of the relationship and to offer... includes investment management and the estate planning...
How can I change this function to get this output?