Am experimenting using the standard Wordpress search and am by using this code within the functions file to focus on looked terms within the displayed results content.

function search_content_highlight() {$content = get_the_content();
$keys = implode('|', explode(' ', get_search_query()));
$content = preg_replace
('/(' . $keys .')/iu', '<strong class="search-  highlight">\0</strong>', $content);
echo '<p>' . $content . '</p>';
}

Am while using content instead of excerpt therefore it always really shows the appropriate word, but Id love to trim this content, therefore it only agreed to be twelve approximately words each side from the looked word, that is locked in the strong tags within the above code. Am pretty a new comer to all of this but am wishing someone can point me within the right direction if this type of trim can be done.

Thanks ahead of time for just about any help!!

I'm speculating that you will wish to show the absolute minimum of all the bolded words. To complete you need to find in which you find the foremost and last demonstration of a matched up word.

function search_content_highlight()
{
    $content = get_the_content();
    $keysArray = explode(' ', get_search_query());
    $keys = implode('|', $keysArray);
    $content = preg_replace('/(' . $keys .')/iu', '<strong class="search-highlight">\0</strong>', $content);
    $minLength = 150; //Number of Characters you want to display minimum 
    $start = -1;
    $end = -1;
    foreach($keysArray as $term)
    {
        $pos = strpos($content, $term);
        if(!($pos === false))
        {
            if($start == -1 || $pos<$start)
                $start = $pos-33; //To take into account the <strong class="search-highlight">
            if($end == -1 || $pos+strlen($term)>$end)
                $end = $pos+strlen($term)+9; //To take into account the full string and the </strong>
        }
    }
    if(strlen($content) < $minLength)
    {
        $start = 0;
        $end = strlen($content);
    }
    if($start == -1 && $end == -1)
    {
        $start =0;
        $end = $minLength;
    }
    else if($start != -1 && $end == -1)
    {
        $start = ($start+$minLength <= strlen($content))?$start:strlen($content)-$minLength;
        $end = $start + $minLength;
    }
    else if($start == -1 && $end !=-1)
    {
        $end = ($end-$minLength >= 0)?$end:$minLength;
        $start = $end-$minLength;
    }
    echo "<p>".(($start !=0)?'...':'').substr($content,$start,$end-$start).(($end !=strlen($content))?'...':'')."</p>";   
}    

I've examined the above mentioned code and delay pills work. You might like to attempt to add more logic in to possess a max description size

Why don't you only use a wordpress plugin?

WordPress Highlight Search Terms

Also, if you are searching to truncate the $content variable, do this function:

function limit_text($text, $limit) {
    if (strlen($text) > $limit) {
        $words = str_word_count($text, 2);
        $pos = array_keys($words);
        $text = substr($text, 0, $pos[$limit]) . '...';
    }

    return $text;
}

from here