PDA

View Full Version : استخراج خلاصه متن از محتوای متن



artablog
شنبه 13 آذر 1395, 00:40 صبح
با استفاده از تابع زیر خلاصه متن را از محتوای متن استخراج میکنم و کلمه جستجو شده را هایلایت میکنم


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('&nbsp;', ' ', $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);

مثلا فرض کنید با کلمه "the centre includes" متن زیر پیدا شده


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



حالا میخوام خروجی به این صورت نشون بده


at thecentre of the relationship and to offer... includes investment management and the estate planning...